-
Notifications
You must be signed in to change notification settings - Fork 3
subsets
Subhajit Sahu edited this page Dec 8, 2022
·
2 revisions
List all possible subsets.
Similar: subsets, hasSubset, randomSubset.
function subsets(x, n)
// x: an object
// n: number of entries [-1 ⇒ any]
const object = require('extra-object');
var x = {a: 1, b: 2};
[...object.subsets(x)];
// → [ {}, { a: 1 }, { b: 2 }, { a: 1, b: 2 } ]
var x = {a: 1, b: 2, c: 3};
[...object.subsets(x)];
// → [
// → {},
// → { a: 1 },
// → { b: 2 },
// → { a: 1, b: 2 },
// → { c: 3 },
// → { a: 1, c: 3 },
// → { b: 2, c: 3 },
// → { a: 1, b: 2, c: 3 }
// → ]