UNPKG

@extra-array/chunk

Version:

Breaks array into chunks of given size.

56 lines (43 loc) 1.94 kB
Breaks array into chunks of given size. [:package:](https://www.npmjs.com/package/@extra-array/chunk) [:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array) [:running:](https://npm.runkit.com/@extra-array/chunk) [:vhs:](https://asciinema.org/a/332025) [:moon:](https://www.npmjs.com/package/@extra-array/chunk.min) [:scroll:](https://unpkg.com/@extra-array/chunk/) [:newspaper:](https://nodef.github.io/extra-array/) [:blue_book:](https://github.com/nodef/extra-array/wiki/) > This is part of package [extra-array]. [extra-array]: https://www.npmjs.com/package/extra-array <br> ```javascript array.chunk(x, [n], [s]); // x: an array // n: chunk size (1) // s: chunk step (n) ``` ```javascript const array = require("extra-array"); var x = [1, 2, 3, 4, 5, 6, 7, 8]; array.chunk(x, 3); // [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ] array.chunk(x, 2, 3); // [ [ 1, 2 ], [ 4, 5 ], [ 7, 8 ] ] array.chunk(x, 4, 3); // [ [ 1, 2, 3, 4 ], [ 4, 5, 6, 7 ], [ 7, 8 ] ] ``` <br> <br> ## References - [List-Extra.groupsOf: elm](https://package.elm-lang.org/packages/elm-community/list-extra/7.1.0/List-Extra#groupsOf) - [iterable_chunk: PHP](https://www.php.net/manual/en/function.iterable-chunk.php) - [array_chunk: PHP](https://www.php.net/manual/en/function.array-chunk.php) - [str_split: PHP](https://www.php.net/manual/en/function.str-split.php) - [numpy.split: Python](https://docs.scipy.org/doc/numpy/reference/generated/numpy.split.html) - [_.chunk: lodash](https://lodash.com/docs/4.17.15#chunk) - [Array.inGroupsOf: sugarjs](https://sugarjs.com/docs/#/Array/inGroupsOf) - [Array.inGroups: sugarjs](https://sugarjs.com/docs/#/Array/inGroups) - [even-chunks: @addaleax](https://www.npmjs.com/package/even-chunks) - [chunk: @ryancole](https://www.npmjs.com/package/chunk) - [iterable.chunk: @zhiyelee](https://www.npmjs.com/package/iterable.chunk) - [chunk-iterable: @haio](https://www.npmjs.com/package/chunk-iterable)