Created
December 13, 2017 21:48
-
-
Save kevinji/5521a94f64dc408cced9438bdfb4e1c3 to your computer and use it in GitHub Desktop.
Find the powerset of an array.
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
// Source: https://stackoverflow.com/a/42774138/558592 (slightly tweaked) | |
function powerset(arr) { | |
return (Array.from({ length: 1 << arr.length }, (_, k) => k) | |
.map(i => arr.filter((_, j) => i & (1 << j)))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment