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