프로그래머스 - n^2 배열 자르기
part18. n^2 배열 자르기
js ver 1.0
function solution(n, left, right) {
return Array(right - left + 1).fill(left)
.map((el, idx) => Math.max(Math.floor((el + idx) / n), (el + idx) % n) + 1);
}
js ver 1.1
function solution(n, left, right) {
return Array.from({length: right - left + 1}, (v, idx) =>
Math.max(Math.floor((left + idx) / n), (left + idx) % n) + 1
);
}