@extra-array/split-at
Version:
Breaks iterable considering indices as separator.
53 lines (39 loc) • 1.69 kB
Markdown
Breaks iterable considering indices as separator.
[:package:](https://www.npmjs.com/package/@extra-array/split-at)
[:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array)
[:running:](https://npm.runkit.com/@extra-array/split-at)
[:vhs:](https://asciinema.org/a/339831)
[:moon:](https://www.npmjs.com/package/@extra-array/split-at.min)
[:scroll:](https://unpkg.com/@extra-array/split-at/)
[: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.splitAt(x, is);
// x: an array
// is: indices (sorted)
```
```javascript
const array = require("extra-array");
var x = [1, 2, 2, 3, 5, 4, 4, 7];
array.splitAt(x, [1, 2, 5, 6]);
// [ [ 1 ], [ 3, 5 ], [ 7 ] ]
var x = [2, 4, 5, 6, 8];
array.splitAt(x, [0, 1, 3, 4]);
// [ [ 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)
[split]: https://github.com/nodef/extra-array/wiki/split
[splitAt]: https://github.com/nodef/extra-array/wiki/splitAt
[cut]: https://github.com/nodef/extra-array/wiki/cut
[group]: https://github.com/nodef/extra-array/wiki/group