

function solution(array, commands) {
var start, end , choice;
commands.map((command)=> {
start =command[0];
end = command[1];
choice = command[2]
answer.push(array.slice(start-1, end).sort((a,b)=>a-b)[choice-1]);
})
return answer;
}
const의 변수를 사용하여 변하지 않는 값으로 명시하여 필요없는 스코프를 삭제하였다
더 간결하고 짧은 코드로 구현!
function solution(array, commands) {
let answer = [];
for(const command of commands){
let commandArray = array.slice(command[0]-1, command[1]);
commandArray.sort((a,b)=> a- b);
answer.push(commandArray[command[2]-1])
}
return answer;
}