배열 조합 순열 알고리즘
조합 Input: [1, 2, 3, 4] Output: [ [1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4] ] const getCombinations = function (arr, selectNumber) { const results = []; if (selectNumber === 1) return arr.map((el) => [el]); // n개중에서 1개 선택할 때(nC1), 바로 모든 배열의 원소 return arr.forEach((fixed, index, origin) => { const rest = origin.slice(index + 1); // 해당하는 fixed를 제외한 나머지 뒤 const combinations = getCombinations(rest, s..
2022. 9. 26.