Files
collection.ts/src/collection/maxWith.ts
Infendro 24838b8f77
All checks were successful
/ publish (push) Successful in 1m24s
Implement Collection
2026-04-27 19:00:49 +02:00

12 lines
334 B
TypeScript

import {error} from "../util/error";
export function maxWith<T>(value: T[], compare: (a: T, b: T) => number): T {
if (value.length === 0) error();
let max = value[0];
for (let index = 1; index < value.length; index++) {
const it = value[index];
if (compare(it, max) > 0) max = it;
}
return max;
}