diff options
| author | okayurisotto <okayurisotto@proton.me> | 2023-07-14 10:45:01 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-14 10:45:01 +0900 |
| commit | 2b6dbd4fcbec380d65b0c318932d9eeb3fcb3f7b (patch) | |
| tree | 125b6f724450c37bd1c025d5b3e09c50dc2b20c9 /packages/frontend/src/scripts | |
| parent | refactor: `substr` -> `substring` (#11273) (diff) | |
| download | sharkey-2b6dbd4fcbec380d65b0c318932d9eeb3fcb3f7b.tar.gz sharkey-2b6dbd4fcbec380d65b0c318932d9eeb3fcb3f7b.tar.bz2 sharkey-2b6dbd4fcbec380d65b0c318932d9eeb3fcb3f7b.zip | |
refactor: 可読性のため一部で`Array.prototype.at`を使うように (#11274)
* refactor: `Array.prototype.at`を使うように
* fixup! refactor: `Array.prototype.at`を使うように
Diffstat (limited to 'packages/frontend/src/scripts')
| -rw-r--r-- | packages/frontend/src/scripts/array.ts | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/packages/frontend/src/scripts/array.ts b/packages/frontend/src/scripts/array.ts index 4620c8b735..c9a146e707 100644 --- a/packages/frontend/src/scripts/array.ts +++ b/packages/frontend/src/scripts/array.ts @@ -78,8 +78,9 @@ export function maximum(xs: number[]): number { export function groupBy<T>(f: EndoRelation<T>, xs: T[]): T[][] { const groups = [] as T[][]; for (const x of xs) { - if (groups.length !== 0 && f(groups[groups.length - 1][0], x)) { - groups[groups.length - 1].push(x); + const lastGroup = groups.at(-1); + if (lastGroup !== undefined && f(lastGroup[0], x)) { + lastGroup.push(x); } else { groups.push([x]); } |