링크
참고
나의 풀이
function solution(array, commands) {
let answer = [];
for (let i = 0; i < commands.length; i++) {
let index = commands[i][2];
answer.push(
array.slice(commands[i][0] - 1, commands[i][1]).sort((a, b) => a - b)[
index - 1
]
);
}
return answer;
}
map, filter, 비구조화할당을 활용한 풀이(이해하려는 중...)
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];
});
}