alpha
Login
or
Join now
mary.my.id
/
pkg-array-fns
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
small array utilities
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Overview
Issues
Pulls
Pipelines
feat: pass array to cluster
author
Mary
date
1 year ago
(Feb 21, 2025, 8:05 AM +0700)
commit
37083a24
37083a242ccd6bf1ad7a84ae4fa8ab6bd595ff99
parent
ba76e98a
ba76e98a6d04e32e1150e4cec2e906ae611e7be0
+2
-2
1 changed file
Expand all
Collapse all
Unified
Split
lib
mod.ts
+2
-2
lib/mod.ts
View file
Reviewed
···
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
87
-
export const cluster = <T>(array: T[], predicate: (a: T, b: T) => unknown): T[][] => {
87
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
102
-
if (predicate(prev, item)) {
102
102
+
if (predicate(prev, item, current as [T, ...T[]])) {
103
103
current.push(item);
104
104
} else {
105
105
clusters.push(current = [item]);