-
Notifications
You must be signed in to change notification settings - Fork 1
partition
Subhajit Sahu edited this page Jun 20, 2020
·
26 revisions
Segregates values by test result. 🏃 📼 📦 🌔 📒
Alternatives: partition, partitionAs.
Similar: count, partition.
iterable.partition(x, ft);
// x: an iterable
// ft: test function (v, i, x)
// --> [satisfies, doesnt]
const iterable = require('extra-iterable');
var x = [1, 2, 3, 4];
iterable.partition(x, v => v % 2 == 0);
// [ [ 2, 4 ], [ 1, 3 ] ]
var x = [1, 2, 3, 4, 5];
iterable.partition(x, v => v % 2 == 1);
// [ [ 1, 3, 5 ], [ 2, 4 ] ]