$ gnpm install @sindresorhus/chunkify
Split an iterable into evenly sized chunks
$ npm install @sindresorhus/chunkify
import chunkify from '@sindresorhus/chunkify';
console.log([...chunkify([1, 2, 3, 4], 2)]);
//=> [[1, 2], [3, 4]]
console.log([...chunkify([1, 2, 3, 4], 3)]);
//=> [[1, 2, 3], [4]]
Returns an iterable with the chunks. The last chunk could be smaller.
Type: Iterable
(for example, Array
)
The iterable to chunkify.
Type: number
(integer)
Minimum: 1
The size of the chunks.
Copyright 2013 - present © cnpmjs.org | Home |