function solution(array, commands) {
var answer = [];
for(var i=0; i<commands.length; i++){
var temp = array.slice(commands[i][0]-1, commands[i][1]);
temp = temp.sort((a,b) => a-b);
answer.push(temp[commands[i][2]-1]);
}
return answer;
}
function solution(array, commands) {
return commands.map(command => {
const [i, j, k] = command;
return array.slice(i-1, j).sort((a,b) => a-b)[k-1];
})
}
def solution(array, commands):
result = []
for command in commands :
[i, j, k] = command
result.append( sorted(array[i-1:j])[k-1] )
return result
const num = [2,5,7,1,3,6];
num.sort((a,b) => a-b);
// [1, 2, 3, 5, 6, 7]
num.sort((a,b) => b-a);
// [7, 6, 5, 3, 2, 1]
[3,4,5] 를 출력하고 싶을 때
arr.slice(a, b)
a부터 b미만까지
const num = [1,2,3,4,5,6,7];
num.slice(2,5);
// [3,4,5]
arr[a:b]
a부터 b미만까지
num = [1,2,3,4,5,6,7]
num[2:5]
# [3,4,5]