[Algorithm] 48 week(12.26 ~ 12.31) 2/3

Dev_min·2022년 12월 26일
0

algorithm

목록 보기
154/157

k번째수

function solution(array, commands) {
    let result = [];
    
    commands.forEach((command) => {
        result.push(findCutNumber(array, command))
    })
    
    return result;
}

const findCutNumber = (numbers, command) => {
    const [start, end, idx] = command;
    const sliceNumbers = [...numbers].slice(start - 1, end);
    
    const sortedNumbers = [...sliceNumbers].sort((a, b) => a - b);
 
    return sortedNumbers[idx - 1];
}
profile
TIL record

0개의 댓글