-
Notifications
You must be signed in to change notification settings - Fork 5
partitionEach
Subhajit Sahu edited this page May 3, 2023
·
1 revision
Segregate each distinct value.
Alternatives: partition, partitionEach.
Similar: count, partition.
function partitionEach(x, fm)
// x: an array
// fm: map function (v, i, x)
const xarray = require('extra-array');
var x = [1, 2, 3, 4];
xarray.partitionEach(x, v => v % 2 == 0);
// → Map(2) { false => [ 1, 3 ], true => [ 2, 4 ] }
var x = [1, 2, 3, 4, 5];
xarray.partitionEach(x, v => v % 3);
// → Map(3) { 1 => [ 1, 4 ], 2 => [ 2, 5 ], 0 => [ 3 ] }