summaryrefslogtreecommitdiff
path: root/packages/frontend/src/scripts
diff options
context:
space:
mode:
authorokayurisotto <okayurisotto@proton.me>2023-07-14 10:45:01 +0900
committerGitHub <noreply@github.com>2023-07-14 10:45:01 +0900
commit2b6dbd4fcbec380d65b0c318932d9eeb3fcb3f7b (patch)
tree125b6f724450c37bd1c025d5b3e09c50dc2b20c9 /packages/frontend/src/scripts
parentrefactor: `substr` -> `substring` (#11273) (diff)
downloadsharkey-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.ts5
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]);
}