[Level1] K번째수

Seokhun Yoon·2022년 5월 7일
0
function solution(array, commands) {
  let answer = commands.map((command) => {
    const [i, j, k] = command
    let sliced = array.slice(i-1, j)
    let result = sliced.sort((a,b) => a-b)[k-1]
    return result
  })
  
  return answer;
}

solution(
	[1, 5, 2, 6, 3, 7, 4],
	[
		[2, 5, 3],
		[4, 4, 1],
		[1, 7, 3],
	]
);

// [5, 6, 3]
profile
블록체인 개발자를 꿈꾸다

0개의 댓글