조합
-
[JavaScript] 조합 알고리즘 코드 이해하기JavaScript 2023. 5. 17. 19:10
const getCombinations = (arr, selectNumber) => { const results = [] if (selectNumber === 1) return arr.map((value) => [value]) arr.forEach((fixed, index, origin) => { const rest = origin.slice(index + 1) const combinations = getCombinations(rest, selectNumber - 1) const attached = combinations.map((combination) => [fixed, ...combination]) results.push(...attached) }); return results } const resu..