Skip to content

Instantly share code, notes, and snippets.

@konijn
Last active January 4, 2016 00:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save konijn/8542820 to your computer and use it in GitHub Desktop.
Save konijn/8542820 to your computer and use it in GitHub Desktop.
powerSet
function powerSet( list ){
var set = [],
listSize = list.length,
combinationsCount = (1 << listSize);
for (var i = 1; i < combinationsCount ; i++ , set.push(combination) )
for (var j=0, combination = [];j<listSize;j++)
if ((i & (1 << j)))
combination.push(list[j]);
return set;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment