구조분해를 이용하면 풀이 쉬워진다.
function solution(array, commands) {
var answer = [];
for (let [i,j,k] of commands){
answer.push(array.slice(i-1,j).sort((a,b)=> a-b)[k-1])
}
return answer;
}
function solution(array, commands) {
return commands.map(command => {
const [sPosition, ePosition, position] = command
const newArray = array
.filter((value, fIndex) => fIndex >= sPosition - 1 && fIndex <= ePosition - 1)
.sort((a,b) => a - b)
return newArray[position - 1]
})
}