@extra-entries/partition

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

Usage no npm install needed!

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

README

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

Alternatives: partition, partitionAs.

This is part of package extra-entries.


entries.partition(x, ft);
// x:  entries
// ft: test function (v, k, x)
// → [satisfies, doesnt]
const entries = require("extra-entries");

var x = [["a", 1], ["b", 2], ["c", 3], ["d", 4]];
entries.partition(x, v => v % 2 == 0).map(x => [...x]);
// [ [ [ "b", 2 ], [ "d", 4 ] ], [ [ "a", 1 ], [ "c", 3 ] ] ]

var x = [["a", 1], ["b", 2], ["c", 3], ["d", 4], ["e", 5]];
entries.partition(x, v => v % 2 == 1).map(x => [...x]);
// [ [ [ "a", 1 ], [ "c", 3 ], [ "e", 5 ] ], [ [ "b", 2 ], [ "d", 4 ] ] ]


References