UNPKG

@extra-array/split

Version:

Breaks array considering test as separator.

53 lines (39 loc) 1.68 kB
Breaks array considering test as separator. [:package:](https://www.npmjs.com/package/@extra-array/split) [:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array) [:running:](https://npm.runkit.com/@extra-array/split) [:vhs:](https://asciinema.org/a/332137) [:moon:](https://www.npmjs.com/package/@extra-array/split.min) [:scroll:](https://unpkg.com/@extra-array/split/) [:newspaper:](https://nodef.github.io/extra-array/) [:blue_book:](https://github.com/nodef/extra-array/wiki/) > Alternatives: [split], [splitAt].<br> > Similar: [cut], [split], [group]. > This is part of package [extra-array]. [extra-array]: https://www.npmjs.com/package/extra-array <br> ```javascript array.split(x, fn); // x: an array // fn: test function (v, i, x) ``` ```javascript const array = require("extra-array"); var x = [1, 2, 2, 3, 5, 4, 4, 7]; array.split(x, v => v % 2 === 0); // [ [ 1 ], [ 3, 5 ], [ 7 ] ] var x = [2, 4, 5, 6, 8]; array.split(x, v => v % 2 === 0); // [ [ 5 ] ] ``` <br> <br> ## References - [String.prototype.split: MDN web docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split) - [String.split: Java](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#split(java.lang.String)) - [String.Split: C#](https://docs.microsoft.com/en-us/dotnet/api/system.string.split?view=netcore-3.1) - [explode: PHP](https://www.php.net/manual/en/function.explode.php) [cut]: https://github.com/nodef/extra-array/wiki/cut [split]: https://github.com/nodef/extra-array/wiki/split [splitAt]: https://github.com/nodef/extra-array/wiki/splitAt [group]: https://github.com/nodef/extra-array/wiki/group