@extra-lists/subsets

Lists all possible subsets. :package: :smiley_cat: :running: :vhs: :moon: :scroll: :newspaper: :blue_book:

Usage no npm install needed!

<script type="module">
  import extraListsSubsets from 'https://cdn.skypack.dev/@extra-lists/subsets';
</script>

README

Lists all possible subsets. :package: :smiley_cat: :running: :vhs: :moon: :scroll: :newspaper: :blue_book:

Similar: subset, subsets, isSubset.

This is part of package extra-lists.


lists.subsets(x, [n]);
// x: lists
// n: number of entries (-1 => any)
const lists = require('extra-lists');

var x = [['a', 'b'], [1, 2]];
[...lists.subsets(x)].map(a => [[...a[0]], [...a[1]]]);
// [
//   [ [], [] ],
//   [ [ 'a' ], [ 1 ] ],
//   [ [ 'b' ], [ 2 ] ],
//   [ [ 'a', 'b' ], [ 1, 2 ] ]
// ]

var x = [['a', 'b', 'c'], [1, 2, 3]];
[...lists.subsets(x)].map(a => [[...a[0]], [...a[1]]]);
// [
//   [ [], [] ],
//   [ [ 'a' ], [ 1 ] ],
//   [ [ 'b' ], [ 2 ] ],
//   [ [ 'a', 'b' ], [ 1, 2 ] ],
//   [ [ 'c' ], [ 3 ] ],
//   [ [ 'a', 'c' ], [ 1, 3 ] ],
//   [ [ 'b', 'c' ], [ 2, 3 ] ],
//   [ [ 'a', 'b', 'c' ], [ 1, 2, 3 ] ]
// ]


References