diff options
| author | Kisaragi <48310258+KisaragiEffective@users.noreply.github.com> | 2024-06-22 19:40:55 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-22 19:40:55 +0900 |
| commit | 9368eb3038d5f655b924d53800daaa7e54e08c47 (patch) | |
| tree | 68464d973415816a832b35d6e2c86860a11365e4 /packages/frontend/src/scripts | |
| parent | fix(backend): 自分以外のクリップ内のノート個数が見えるの... (diff) | |
| download | sharkey-9368eb3038d5f655b924d53800daaa7e54e08c47.tar.gz sharkey-9368eb3038d5f655b924d53800daaa7e54e08c47.tar.bz2 sharkey-9368eb3038d5f655b924d53800daaa7e54e08c47.zip | |
refactor: say bye to the weird groupBy friends (#13975)
* refactor(frontend): say bye to the weird groupBy friends
* refactor(backend): say bye to the weird groupBy friends
Diffstat (limited to 'packages/frontend/src/scripts')
| -rw-r--r-- | packages/frontend/src/scripts/array.ts | 38 |
1 files changed, 0 insertions, 38 deletions
diff --git a/packages/frontend/src/scripts/array.ts b/packages/frontend/src/scripts/array.ts index b3d76e149f..f2feb29dfc 100644 --- a/packages/frontend/src/scripts/array.ts +++ b/packages/frontend/src/scripts/array.ts @@ -78,44 +78,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 (typeof obj[key] === 'undefined') { - obj[key] = []; - } - - obj[key].push(item); - - return obj; - }, {}); -} - -/** * Compare two arrays by lexicographical order */ export function lessThan(xs: number[], ys: number[]): boolean { |