Basic usage

Given an array of items and a desired cluster size (n), returns an array of arrays. Each child array containing n (cluster size) items split as evenly as possible.

import { cluster } from 'radash'

const gods = [
  'Ra', 
  'Zeus', 
  'Loki', 
  'Vishnu', 
  'Icarus', 
  'Osiris',
  'Thor'
]

cluster(gods, 3)
// => [
//   [ 'Ra', 'Zeus', 'Loki' ],
//   [ 'Vishnu', 'Icarus', 'Osiris' ],
//   [ 'Thor' ]
// ]

Testing

This _.cluster function is 100% covered by tests. See them and contribute at GitHub.

Source

See the source for _.cluster on GitHub.