반응형 순열1 내가 보려고 만든 순열 조합 중복순열 순열 //순열 const getPermutations = function (arr, selectNumber) { // - 순열을 담을 배열 설정 const results = []; // - base case: 숫자가 한개라면 숫자 그대로 배열로 반환 if (selectNumber === 1) return arr.map((value) => [value]); // - recursive case: arr을 순회하면서 각 숫자들을 fixed하여 첫번째 수로 만든다. arr.forEach((fixed, index, origin) => { // - fixed를 제외한 나머지 배열을 만든다. const rest = [...origin.slice(0, index), ...origin.slice(index + 1)]; .. 2021. 10. 7. 이전 1 다음 반응형