-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
Description
function getAllSubsets(array) {
const subsets = [[]];
for (const el of array) {
const last = subsets.length-1;
for (let i = 0; i <= last; i++) { // 기존 subset 배열에 자신을 추가한 새로운 배열 만들어 push
subsets.push( [...subsets[i], el] );
}
}
return subsets;
}Here is an example for [1, 2, 3]
-
Start with an empty subset: []
-
Create new subsets by adding "1" to each existing subset. It will be:[] [1]
-
Create new subsets by adding "2" to each existing subset. It will be:[], [1] [2], [1, 2]
-
Create new subsets by adding "3" to each existing subset. It will be: [], [1], [2], [1, 2] [3], [1, 3], [2, 3], [1, 2, 3]
참고 : https://stackoverflow.com/questions/42773836/how-to-find-all-subsets-of-a-set-in-javascript
Reactions are currently unavailable