Skip to content

Instantly share code, notes, and snippets.

@io-developer
Last active February 14, 2018 12:07
Show Gist options
  • Save io-developer/8399fc286bffbf28784bd374f3f9892f to your computer and use it in GitHub Desktop.
Save io-developer/8399fc286bffbf28784bd374f3f9892f to your computer and use it in GitHub Desktop.
Sets and combinations
function findSetsIn(list, noEmptySet) {
var result = noEmptySet ? [] : [[]];
for (var i = 0; i < list.length; i++) {
var base = [ list[i] ];
result.push(base);
var tail = findSetsIn(list.slice(i + 1), true);
for (var j = 0; j < tail.length; j++) {
result.push(base.concat(tail[j]));
}
}
return result;
}
findSetsIn([1, 2, 3, 4, 5])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment