@extra-lists/partition-as

Segregates values by similarity. :package: :smiley_cat: :running: :vhs: :moon: :scroll: :newspaper: :blue_book:

Usage no npm install needed!

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

README

Segregates values by similarity. :package: :smiley_cat: :running: :vhs: :moon: :scroll: :newspaper: :blue_book:

Alternatives: partition, partitionAs.

This is part of package extra-lists.


lists.partitionAs(x, [fm]);
// x:  lists
// fm: map function (v, k, x)
// → Map {key => values}
const lists = require('extra-lists');

var x = [['a', 'b', 'c', 'd'], [1, 2, 3, 4]];
lists.partitionAs(x, v => v % 2 == 0);
// Map(2) {
//   false => [ [ 'a', 'c' ], [ 1, 3 ] ],
//   true => [ [ 'b', 'd' ], [ 2, 4 ] ]
// }

var x = [['a', 'b', 'c', 'd', 'e'], [1, 2, 3, 4, 5]];
lists.partitionAs(x, v => v % 3);
// Map(3) {
//   1 => [ [ 'a', 'd' ], [ 1, 4 ] ],
//   2 => [ [ 'b', 'e' ], [ 2, 5 ] ],
//   0 => [ [ 'c' ], [ 3 ] ]
// }


References