A tiny library to split an array into multiple smaller arrays by distributing the elements evenly.
$ npm install --save array-splitter
const split = require('array-splitter');
split([1, 2, 3, 4, 5, 6, 7, 8, 9], 3);
// Returns -> [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
split([1, 2, 3, 4, 5, 6, 7, 8, 9], 4);
// Returns -> [[1, 2, 3], [4, 5], [6, 7], [8, 9]]
split([1, 2, 3, 4, 5, 6, 7, 8, 9], 14);
// Returns -> [[1], [2], [3], [4], [5], [6], [7], [8], [9], [], [], [], [], []]
Required
Type: array
The array to split up. After the split this array will become empty!
Required
Type: number
It must be an integer number greater than zero. The returned array contains exactly bucketCount
number of arrays (i.e. buckets). If the number of item in the items
array is less than this number, some empty arrays will be returned.
MIT