Skip to content

partition

Subhajit Sahu edited this page Mar 16, 2020 · 28 revisions

Splits array into values, which do/dont satisfy the test.

array.partition(x, fn, [ths]);
// x:   an array
// fn:  test function (v, i, x)
// ths: this argument
// --> [[...satisfies], [...doesnt]]
const array = require('extra-array');

array.partition([1, 2, 3, 4], v => v % 2 == 0);
// [ [ 2, 4 ], [ 1, 3 ] ]

array.partition([1, 2, 3, 4, 5], v => v % 2 == 1);
// [ [ 1, 3, 5 ], [ 2, 4 ] ]

references

Clone this wiki locally