Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kavalcante/array-into-subarrays

A non destructive and simple function that divide an array into multiples subarrays
https://github.com/kavalcante/array-into-subarrays

function functional-programming javascript nodejs npm

Last synced: 6 days ago
JSON representation

A non destructive and simple function that divide an array into multiples subarrays

Awesome Lists containing this project

README

        

# Array into Subarrays

[![Build Status](https://travis-ci.org/kavalcante/array-into-subarrays.svg?branch=master)](https://travis-ci.org/kavalcante/array-into-subarrays)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/kavalcante/array-into-subarrays/master/LICENSE)
[![npm version](https://badge.fury.io/js/array-into-subarrays.svg)](https://badge.fury.io/js/array-into-subarrays)

Insert a array list and receive a new list (non destructive) with groups of elements (subarrays).

### Installing

```
$ npm install array-into-subarrays --save
```

### Usage

```js

import arrayIntoSubarrays from 'array-into-subarrays';

const array = [1, 2, 3, 4, 5, 6, 7, 8, 9] // could be any data, and how much indexes do you want.

arrayIntoSubarrays(array, 4) // => [[1, 2, 3, 4], [5, 6, 7, 8], [9]];

// you can invoke the function in any part of your code, because is a non destructive function

```

## Attributes

| Option | Default | Type | Description |
| :------------ | :------------ | :----- | :--------- |
| __array__ | no default value | array | Array that will be divided. |
| __limit__ | 4 | number | Length of subarrays. |

## License

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details

## Acknowledgments

* [copy from Stack Overflow answear](http://stackoverflow.com/questions/11318680/split-array-into-chunks-of-n-length)