Skip to content

partition

Subhajit Sahu edited this page Feb 3, 2021 · 26 revisions

Segregate values by test result.

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


function partition(x, ft)
// x:  an array
// ft: test function (v, i, x)
const xiterable = require('extra-iterable');

var x = [1, 2, 3, 4];
xiterable.partition(x, v => v % 2 == 0);
// → [[2, 4], [1, 3]]

var x = [1, 2, 3, 4, 5];
xiterable.partition(x, v => v % 2 == 1);
// → [[1, 3, 5], [2, 4]]


References

Clone this wiki locally