https://github.com/shinnn/array-divide
Divide an array into multiple arrays each of whom have the same number of items
https://github.com/shinnn/array-divide
Last synced: 4 months ago
JSON representation
Divide an array into multiple arrays each of whom have the same number of items
- Host: GitHub
- URL: https://github.com/shinnn/array-divide
- Owner: shinnn
- License: mit
- Created: 2015-01-23T19:56:11.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2018-12-06T19:17:00.000Z (almost 7 years ago)
- Last Synced: 2025-06-28T11:08:53.876Z (5 months ago)
- Language: JavaScript
- Homepage: https://npm.runkit.com/array-divide
- Size: 29.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# array-divide
[](https://www.npmjs.com/package/array-divide)
[](https://travis-ci.com/shinnn/array-divide)
[](https://coveralls.io/github/shinnn/array-divide)
Divide an `Array` into multiple `Array`s each of whom have the same number of items
```javascript
arrayDivide(['a', 'b', 'c', 'd'], 2); //=> [['a', 'b'], ['c', 'd']]
arrayDivide(['a', 'b', 'c', 'd'], 3); //=> [['a', 'b', 'c'], ['d']]
```
## Installation
[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/about-npm/).
```
npm install array-divide
```
## API
```javascript
import arrayDivide from 'array-divide';
```
### arrayDivide(*array*, *count*)
*array*: `Array`
*count*: `number` (the maximum number of items)
Return: `Array` (a new array and doesn't break the original one)
```javascript
arrayDivide(['a', 'b', 'c', 'd'], 100); //=> [['a', 'b', 'c', 'd']]
arrayDivide([], 100); //=> []
arrayDivide(['a', 'b', 'c'], 0); // throw an error (count must be >= 1)
arrayDivide(new Set(), 1); // throw an error (doesn't support array-like object)
```
## License
Copyright (c) 2015 - 2018 [Shinnosuke Watanabe](https://github.com/shinnn)
Licensed under [the MIT License](./LICENSE).