Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.