Skip to content

splitAt

Subhajit Sahu edited this page Jun 15, 2020 · 9 revisions

Breaks iterable considering test as separator. 🏃 📼 📦 🌔 📒

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

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

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

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

references

Clone this wiki locally