node package manager
Easy sharing. Manage teams and permissions with one click. Create a free org »

partition-all

partition-all

Build Status npm version

Returns a sequence of arrays, but may include partitions with fewer than n items at the end.

Installation

npm install partition-all --save

Usage

var partitionAll = require('partition-all');
 
partitionAll(2, [1, 2, 3, 4, 5, 6]); // => [[1, 2], [3, 4], [5, 6]] 
partitionAll(2, [1, 2, 3, 4, 5]); // => [[1, 2], [3, 4], [5]] 
partitionAll(3, [1, 2, 3, 4, 5]); // => [[1, 2, 3], [4, 5]] 
 
var partition2 = partitionAll(2);
 
partition2([1, 2, 3, 4, 5, 6]); // => [[1, 2], [3, 4], [5, 6]]