๋ฌธ์ ๐ฝ
https://school.programmers.co.kr/learn/courses/30/lessons/42748
๋ค๋ฅธ์ฌ๋ ํ์ด ๐ฝ
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]
})
}
๋ดํ์ด๐ฝ
1. ์ฑ๊ณต โญ
function solution(array, commands) {
var answer = [];
commands.forEach((command,inedx)=>{
let t = array.slice(command[0]-1,command[1])
t.sort((a,b)=>a-b)
answer.push(t[command[2]-1])
})
return answer;
}
๋๋์ ๐ฝ
command[0] ,[1], [2] ์ด๋ ๊ฒ ์ฐ๋ ๊ฒ ๋ณด๋จ
let [sPosition, ePosition, position ] = command ์ด๋ ๊ฒ ๊ตฌ์กฐ ๋ถํด ํ ๋นํจ์ผ๋ก์จ ์ฝ๋์ ๊ฐ๋ ์ฑ์ ๋์ด๋ ํ ํฌ๋์ด ์ธ์ ๊น์๋ค.