Skip to content

Instantly share code, notes, and snippets.

@io-developer
Last active March 4, 2018 16:25
Show Gist options
  • Save io-developer/12ec2c6f3317e822cfb5d4b6e3f2ffd1 to your computer and use it in GitHub Desktop.
Save io-developer/12ec2c6f3317e822cfb5d4b6e3f2ffd1 to your computer and use it in GitHub Desktop.
binary sets
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