Splits a single list into many lists of the desired size.
cluster([1, 2, 3, 4, 5, 6], 2); // [[1, 2], [3, 4], [5, 6]]
npx atmx add helper cluster
Copy and paste the following method into @/utils/helpers/undefined.ts:
@/utils/helpers/undefined.ts
/*** Splits a single list into many lists of the desired size.** @example* cluster([1, 2, 3, 4, 5, 6], 2) // [[1, 2], [3, 4], [5, 6]]*/export function cluster<T>(array: readonly T[], size = 2): T[][] {const clusters: T[][] = [];for (let i = 0; i < array.length; i += size) {clusters.push(array.slice(i, i + size));}return clusters;}