Created
July 23, 2015 17:10
-
-
Save gartenfeld/f5e3006df8d082a2d29a to your computer and use it in GitHub Desktop.
Generating a powerset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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