Revert "refactor: 可読性のため一部でArray.prototype.at
を使うように" (#115)
* Revert "refactor: 可読性のため一部で`Array.prototype.at`を使うように (#11274)"
This reverts commit 2b6dbd4fcb
.
* Apply suggestions from code review
---------
Co-authored-by: okayurisotto <okayurisotto@proton.me>
This commit is contained in:
@@ -67,9 +67,8 @@ 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) {
|
||||
const lastGroup = groups.at(-1);
|
||||
if (lastGroup !== undefined && f(lastGroup[0], x)) {
|
||||
lastGroup.push(x);
|
||||
if (groups.length !== 0 && f(groups[groups.length - 1][0], x)) {
|
||||
groups[groups.length - 1].push(x);
|
||||
} else {
|
||||
groups.push([x]);
|
||||
}
|
||||
|
Reference in New Issue
Block a user