-
Notifications
You must be signed in to change notification settings - Fork 0
partition
Subhajit Sahu edited this page Jun 18, 2020
·
15 revisions
Segregates values by test result. 🏃 📼 📦 🌔 📒
Alternatives: partition, partitionAs.
lists.partition(x, ft);
// x: lists
// 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 ] ] ]