fn
cluster
v0.0.3testedCluster an array into subarrays of a specific size
Examples
ts
cluster([1, 2, 3, 4, 5, 6, 7, 8], 3) // => [[1, 2, 3], [4, 5, 6], [7, 8]]ts
cluster([1, 2, 3, 4], -1) // => []Signature
ts
export function cluster<Value>(arr: Value[], size: number): Value[][]{ ... }Type Parameters
ValueParameters
| Parameter | Type | Description |
|---|---|---|
arr | Value[] | The array to cluster |
size | number | The size of each cluster |
Returns
Value[][]The clustered array