function solution(array, commands) {
var answer = [];
var st = 0;
var ed = 0;
var ct = 0;
for(let i = 0 ;i < commands.length ; i ++){
for(let j = 0 ; j < commands[i].length ; j++){
if( j === 0 ) st =commands[i][j];
if( j === 1 ) ed =commands[i][j];
if( j === 2 ) ct =commands[i][j];
}
var temp = array.slice(st -1 ,ed); // 1
// 2
temp.sort((a,b)=> {
return a - b;
})
answer.push(temp[ct - 1])
console.log(answer)
}
return answer;
}
기존 배열 변형하지 않기 위해 slice
사용 , splice
는 기존 배열을 변형
정렬 기준 함수가 없으면 유니코드로 정렬됨.