1.0.0 • Published 4 years ago

array-splitter v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

array-splitter

A tiny library to split an array into multiple smaller arrays by distributing the elements evenly.

How to install

$ npm install --save array-splitter

How to use

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], [], [], [], [], []]

Documentation

split(items, bucketCount)

items

Required
Type: array

The array to split up. After the split this array will become empty!

bucketCount

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.

License

MIT