function solution (array, commands){
var answer = [];
for (var i = 0; i < commands.length; i++){
var sliceArray = temp.slice(commands[i][0]-1,commands[i][1]);
sliceArray.sort((a,b) => a-b);
answer.push(sliceArray[commands[i][2]-1]);
}
return answer ;
}
.splice()
array.splice(start[, deleteCount[, item1[, item2[, ...]]]])
매개변수
반환 값 : 제거한 요소를 담은 배열
.sort()
arr.sort([compareFunction])
// 문자열 비교
function compare(a, b) {
if (a < b) return -1; //a가 b보다 작을 경우
if (a > b) return 1; //a가 b보다 클 경우
return 0; // a랑 b가 같을 경우
// 숫자 비교
function compare((a, b) => a-b);
arr.push(element1[, ...[, elementN]])
const animals = ['pigs', 'goats', 'sheep'];
const count = animals.push('cows');
console.log(count);
// output : 4
console.log(animals);
// output : Array ["pigs", "goats", "sheep", "cows"]
push() 반환 값은 배열의 길이
자꾸 변수 하나를 선언해서 거기에 push 반환 값을 저장했는데 그렇게 하면 배열의 길이만 나오기 때문에 계속 틀렸던 것 같다.. 왜 그렇게 한걸까 ?ㅎ