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