Skip to content

Instantly share code, notes, and snippets.

@alexislagante
Created November 7, 2015 06:30
Show Gist options
  • Save alexislagante/b962b23c8adac849d8e3 to your computer and use it in GitHub Desktop.
Save alexislagante/b962b23c8adac849d8e3 to your computer and use it in GitHub Desktop.
Generate the powerset of a given string
function powerSet(str) {
var chars = str.split("");
var result = [""];
chars.forEach(function(v){
var newResult = [];
result.forEach(function(item) {
newResult.push(item+v);
});
result = result.concat(newResult);
});
return result;
}
powerSet("abcd");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment