Created
November 7, 2015 06:30
-
-
Save alexislagante/b962b23c8adac849d8e3 to your computer and use it in GitHub Desktop.
Generate the powerset of a given string
This file contains 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(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