Skip to content

Instantly share code, notes, and snippets.

@gartenfeld
Created July 23, 2015 17:10
Show Gist options
  • Save gartenfeld/f5e3006df8d082a2d29a to your computer and use it in GitHub Desktop.
Save gartenfeld/f5e3006df8d082a2d29a to your computer and use it in GitHub Desktop.
Generating a powerset
function powerset(alphabet) {
var p = [[]];
for (var i=0; i < alphabet.length; i++) {
// here the value of len is set at the beginning
for (var j = 0, l = p.length; j < l; j++) {
p.push(p[j].concat(alphabet[i]));
// inspector
console.log(p);
}
}
return p;
}
// test
powerset(['a','b','c']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment