diff options
Diffstat (limited to 'packages/backend/src/misc/prelude/array.ts')
| -rw-r--r-- | packages/backend/src/misc/prelude/array.ts | 38 |
1 files changed, 0 insertions, 38 deletions
diff --git a/packages/backend/src/misc/prelude/array.ts b/packages/backend/src/misc/prelude/array.ts index bd6c8ee8e3..f6c43b4ef4 100644 --- a/packages/backend/src/misc/prelude/array.ts +++ b/packages/backend/src/misc/prelude/array.ts @@ -66,44 +66,6 @@ export function maximum(xs: number[]): number { } /** - * Splits an array based on the equivalence relation. - * The concatenation of the result is equal to the argument. - */ -export function groupBy<T>(f: EndoRelation<T>, xs: T[]): T[][] { - const groups = [] as T[][]; - for (const x of xs) { - const lastGroup = groups.at(-1); - if (lastGroup !== undefined && f(lastGroup[0], x)) { - lastGroup.push(x); - } else { - groups.push([x]); - } - } - return groups; -} - -/** - * Splits an array based on the equivalence relation induced by the function. - * The concatenation of the result is equal to the argument. - */ -export function groupOn<T, S>(f: (x: T) => S, xs: T[]): T[][] { - return groupBy((a, b) => f(a) === f(b), xs); -} - -export function groupByX<T>(collections: T[], keySelector: (x: T) => string) { - return collections.reduce((obj: Record<string, T[]>, item: T) => { - const key = keySelector(item); - if (!Object.prototype.hasOwnProperty.call(obj, key)) { - obj[key] = []; - } - - obj[key].push(item); - - return obj; - }, {}); -} - -/** * Compare two arrays by lexicographical order */ export function lessThan(xs: number[], ys: number[]): boolean { |