문제
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
메모
splice는 배열의 원본 일부를 삭제하거나 교체한다.
splice(start)
splice(start, deleteCount)
splice(start, deleteCount, item1)
splice(start, deleteCount, item1, item2, itemN)
정답
function solution(num_list, n) {
const answer = [];
// num_list에 값이 있으면 n개씩 자른다
// 해당 값을 answer에 넣는다
while (num_list.length > 0) {
answer.push(num_list.splice(0, n));
}
return answer;
}