Last active
March 4, 2018 16:25
-
-
Save io-developer/12ec2c6f3317e822cfb5d4b6e3f2ffd1 to your computer and use it in GitHub Desktop.
binary sets
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 setsOf(list) { | |
var l = list.length; | |
var sets = []; | |
var total = 1 << l; | |
for (var i = 0; i < total; i++) { | |
var sub = []; | |
for (var j = 0; j < l; j++) { | |
if (i & (1 << j)) { | |
sub.push(list[j]); | |
} | |
} | |
sets.push(sub); | |
} | |
return sets; | |
} | |
setsOf([1,2,3,4]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment