-
Notifications
You must be signed in to change notification settings - Fork 5
partition
Subhajit Sahu edited this page May 3, 2023
·
28 revisions
Segregate values by test result.
Alternatives: partition, partitionEach.
Similar: count, partition.
function partition(x, ft)
// x: an array
// ft: test function (v, i, x)
const xarray = require('extra-array');
var x = [1, 2, 3, 4];
xarray.partition(x, v => v % 2 == 0);
// → [ [ 2, 4 ], [ 1, 3 ] ]
var x = [1, 2, 3, 4, 5];
xarray.partition(x, v => v % 2 == 1);
// → [ [ 1, 3, 5 ], [ 2, 4 ] ]