Implement sequence

This commit is contained in:
2026-04-25 20:55:50 +02:00
parent e2a18101cf
commit a5866c08ff
62 changed files with 570 additions and 569 deletions

View File

@@ -1,14 +1,13 @@
export function minByOrNull<T>(value: Iterable<T>, transform: (it: T) => number): T | null {
let minIt!: T;
let min!: number;
let found = false;
let minVal: number | undefined;
for (const it of value) {
const val = transform(it);
if (found && val >= min) continue;
minIt = it;
min = val;
found = true;
if (minVal === undefined || val < minVal) {
minIt = it;
minVal = val;
}
}
if (!found) return null;
if (minVal === undefined) return null;
return minIt;
}