WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

splitAt

Subhajit Sahu edited this page May 3, 2023 · 13 revisions

Break array considering indices as separator.

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


function splitAt(x, is)
// x:  an array
// is: indices (sorted)
const xarray = require('extra-array');

var x = [1, 2, 2, 3, 5, 4, 4, 7];
xarray.splitAt(x, [1, 2, 5, 6]);
// → [ [ 1 ], [ 3, 5 ], [ 7 ] ]

var x = [2, 4, 5, 6, 8];
xarray.splitAt(x, [0, 1, 3, 4]);
// → [ [ 5 ] ]


References

Clone this wiki locally