-
Notifications
You must be signed in to change notification settings - Fork 5
partition
wolfram77 edited this page Apr 13, 2020
·
28 revisions
Segregates array keeping similar values together. 🏃 📼 📦 🌔
array.partition(x, fn, [ths]);
// x: an array
// fn: test function (v, i, x)
// ths: this argument
// --> [satisfies, doesnt]
const array = require('extra-array');
var x = [1, 2, 3, 4];
array.partition(x, v => v % 2 == 0);
// [ [ 2, 4 ], [ 1, 3 ] ]
var x = [1, 2, 3, 4, 5];
array.partition(x, v => v % 2 == 1);
// [ [ 1, 3, 5 ], [ 2, 4 ] ]