Created
January 13, 2020 22:12
-
-
Save amejiarosario/0125c4bf7596e28989f9a31e3917d8ce to your computer and use it in GitHub Desktop.
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(n = '') { | |
const array = Array.from(n); | |
const base = ['']; | |
const results = array.reduce((previous, element) => { | |
const previousPlusElement = previous.map(el => { | |
return `${el}${element}`; | |
}); | |
return previous.concat(previousPlusElement); | |
}, base); | |
return results; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment