Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 27 days 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 10 years ago)
- Default Branch: master
- Last Pushed: 2018-12-06T19:17:00.000Z (almost 6 years ago)
- Last Synced: 2024-10-11T22:47:27.381Z (about 1 month 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
[![npm version](https://img.shields.io/npm/v/array-divide.svg)](https://www.npmjs.com/package/array-divide)
[![Build Status](https://travis-ci.com/shinnn/array-divide.svg?branch=master)](https://travis-ci.com/shinnn/array-divide)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/array-divide.svg)](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).