-
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 lists = require('extra-lists');
var x = [['a', 'b', 'c', 'd'], [1, 2, 3, 4]];
lists.partition(x, v => v % 2 == 0).map(x => [...x]);
// [ [ [ 'b', 'd' ], [ 2, 4 ] ], [ [ 'a', 'c' ], [ 1, 3 ] ] ]
var x = [['a', 'b', 'c', 'd', 'e'], [1, 2, 3, 4, 5]];
lists.partition(x, v => v % 2 == 1).map(x => [...x]);
// [ [ [ 'a', 'c', 'e' ], [ 1, 3, 5 ] ], [ [ 'b', 'd' ], [ 2, 4 ] ] ]