small array utilities
0

Configure Feed

Select the types of activity you want to include in your feed.

feat: pass array to cluster

+2 -2
+2 -2
lib/mod.ts
··· 84 84 * @returns an array of clusters, where each cluster is an array of consecutive elements that satisfy the predicate 85 85 */ 86 86 /*#__NO_SIDE_EFFECTS__*/ 87 - export const cluster = <T>(array: T[], predicate: (a: T, b: T) => unknown): T[][] => { 87 + export const cluster = <T>(array: T[], predicate: (a: T, b: T, array: [T, ...T[]]) => unknown): T[][] => { 88 88 const len = array.length; 89 89 90 90 if (len === 0) { ··· 99 99 for (let idx = 1; idx < len; idx++) { 100 100 const item = array[idx]; 101 101 102 - if (predicate(prev, item)) { 102 + if (predicate(prev, item, current as [T, ...T[]])) { 103 103 current.push(item); 104 104 } else { 105 105 clusters.push(current = [item]);