Skip to content

partition

Subhajit Sahu edited this page Feb 2, 2021 · 28 revisions

Segregates values by test result. 🏃 📼 📦 🌔 📒

Alternatives: partition, partitionAs.
Similar: count, partition.


array.partition(x, ft);
// x:  an array
// ft: test function (v, i, x)
// --> [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 ] ]


References

Clone this wiki locally