Implement Collection
All checks were successful
/ publish (push) Successful in 1m24s

This commit is contained in:
2026-04-27 19:00:49 +02:00
parent 6c7fad267c
commit 24838b8f77
88 changed files with 1153 additions and 10 deletions

16
src/collection/minBy.ts Normal file
View File

@@ -0,0 +1,16 @@
import {error} from "../util/error";
export function minBy<T>(value: T[], transform: (it: T) => number): T {
if (value.length === 0) error();
let min = value[0];
let minVal = transform(min);
for (let index = 1; index < value.length; index++) {
const it = value[index];
const val = transform(it);
if (val < minVal) {
min = it;
minVal = val;
}
}
return min;
}