Skip to content

partition

wolfram77 edited this page Mar 27, 2020 · 26 revisions

Breaks iterable into values, by test.

Alternatives: compare, map.

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

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

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

references

Clone this wiki locally