Skip to content
Subhajit Sahu edited this page May 3, 2023 · 25 revisions

Break array considering test as separator.

Alternatives: split, splitAt.
Similar: cut, split, group.


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

var x = [1, 2, 2, 3, 5, 4, 4, 7];
xarray.split(x, v => v % 2 === 0);
// → [ [ 1 ], [ 3, 5 ], [ 7 ] ]

var x = [2, 4, 5, 6, 8];
xarray.split(x, v => v % 2 === 0);
// → [ [ 5 ] ]


References

Clone this wiki locally