Skip to content

Instantly share code, notes, and snippets.

@noonat
Created February 3, 2012 22:18
Show Gist options
  • Save noonat/1733255 to your computer and use it in GitHub Desktop.
Save noonat/1733255 to your computer and use it in GitHub Desktop.
Power sets
powerSet = (set) ->
p = [[]]
for val in set
for i in [0...p.length]
p[p.length] = p[i].concat([val])
p
var powerSet = function(set) {
var p = [[]];
for (var i = 0, il = set.length; i < il; ++i) {
var val = set[i];
for (var j = 0, jl = p.length; j < jl; ++j) {
p[p.length] = p[j].concat([val])
}
}
return p;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment