Created
November 15, 2017 06:55
-
-
Save alextanhongpin/dacc5cf4143b34e6b42bd8a0dbf2f23d to your computer and use it in GitHub Desktop.
Create different combinations from array
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 combination (x) { | |
return Array(Math.pow(2, x.length)).fill(0).map((_, i) => { | |
return Array(x.length).fill(0).map((_, j) => { | |
if ((i & Math.pow(2, j))) { | |
return x[j] | |
} | |
return null | |
}).filter((nonNull => nonNull !== null)) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment