Skip to content

Instantly share code, notes, and snippets.

@MaxXxiMast
Last active November 26, 2019 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaxXxiMast/d3bad021172d78eab1c5568e901fa4bc to your computer and use it in GitHub Desktop.
Save MaxXxiMast/d3bad021172d78eab1c5568e901fa4bc to your computer and use it in GitHub Desktop.
const superSet = arr => {
var result = [];
result.push([])
arr.forEach(val => {
let length = result.length;
let i = 0;
while(i < length){
let newAr = result[i].slice(0);
newAr.push(val);
result.push(newAr);
i++;
}
});
return result;
}
const setArr = [1,2,3]
const superSetArr = superSet(setArr); //[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment