small array utilities
0

Configure Feed

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

fix: adjust type signature for cluster

+7 -4
+7 -4
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, array: [T, ...T[]]) => unknown): T[][] => { 87 + export const cluster = <T>( 88 + array: T[], 89 + predicate: (a: T, b: T, array: [T, ...T[]]) => unknown, 90 + ): [T, ...T[]][] => { 88 91 const len = array.length; 89 92 90 93 if (len === 0) { ··· 92 95 } 93 96 94 97 let prev = array[0]; 95 - let current = [prev]; 98 + let current: [T, ...T[]] = [prev]; 96 99 97 - const clusters: T[][] = [current]; 100 + const clusters = [current]; 98 101 99 102 for (let idx = 1; idx < len; idx++) { 100 103 const item = array[idx]; 101 104 102 - if (predicate(prev, item, current as [T, ...T[]])) { 105 + if (predicate(prev, item, current)) { 103 106 current.push(item); 104 107 } else { 105 108 clusters.push(current = [item]);