https://programmers.co.kr/learn/courses/30/lessons/42748#
코딩테스트 연습 - K번째수
[1, 5, 2, 6, 3, 7, 4] [[2, 5, 3], [4, 4, 1], [1, 7, 3]] [5, 6, 3]
programmers.co.kr
javascript기본 소트를 처리 할 경우 number라고 해도 1,10,2 이런식으로 소팅처리 된다.
반듯이 comparator를 만들어 줘야 한다.
그리고 boolean 처리는 더 이상 지원하지 않는다.
function solution(array, commands) {
var answer = [];
for(let command of commands){
answer.push((array.slice(command[0]-1, command[1]).sort(((a,b)=>a-b)))[command[2]-1]);
}
return answer;
}
728x90
반응형
'Problem Solving' 카테고리의 다른 글
| 가운데 글자 가져오기 (0) | 2020.09.02 |
|---|---|
| 2016년 (0) | 2020.09.02 |
| 체육복 그리고 테스트케이스 5 (0) | 2020.09.02 |
| 모의고사 (0) | 2020.09.02 |
| 완주하지 못한 선수 (0) | 2020.09.02 |