partition-into

Partition an array into required sets of n numbers, and the remaining values

Usage no npm install needed!

<script type="module">
  import partitionInto from 'https://cdn.skypack.dev/partition-into';
</script>

README

partition-into

Partition an array into required sets of n numbers, and the remaining values

Build Status

js-semistandard-style

Install

$ npm install --save partition-into

Usage

var partitionInto = require('partition-into');

partitionInto([1, 2, 3, 4, 5], 3);
//=> [[1, 2, 3], [4, 5]]

partitionInto([1, 2, 3, 4, 5, 6, 7], 5);
//=> [[1, 2, 3, 4, 5], [6, 7]]

partitionInto([1, 2, 3, 4, 5]);
//=> [ [ ] ]

API

partitionInto(input_obj, num)

input_obj

Required
Type: Array

Input 1-dimensional array

num

Required
Type: integer
Default: undefined

Number of items per partition

License

MIT © Siddharth Kannan