array-splitter

1.0.0 • Public • Published

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

Package Sidebar

Install

npm i array-splitter

Weekly Downloads

1

Version

1.0.0

License

ISC

Unpacked Size

2.43 kB

Total Files

3

Last publish

Collaborators

  • abdullahalbakee