@extra-lists/submaps

Lists all possible submaps. [:running:] [:vhs:] [:package:] [:moon:] [:ledger:] > Similar: [subobject], [subobjects], [isSubobject]. > This is part of package extra-lists.

Usage no npm install needed!

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

README

Lists all possible submaps. :running: :vhs: :package: :moon: :ledger:

Similar: subobject, subobjects, isSubobject.
This is part of package extra-lists.

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

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

var x = [['a', 'b', 'c'], [1, 2, 3]];
[...lists.submaps(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