Skip to content

cluster
109 bytes

Split a list into many lists of the given size

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 * as _ from 'radashi'
const gods = [
'Ra',
'Zeus',
'Loki',
'Vishnu',
'Icarus',
'Osiris',
'Thor',
'Apollo',
'Artemis',
'Athena',
]
const clustered = _.cluster(gods, 3)
// => [
// ['Ra', 'Zeus', 'Loki'],
// ['Vishnu', 'Icarus', 'Osiris'],
// ['Thor', 'Apollo', 'Artemis'],
// ['Athena']
// ]