DRAFT: implement sequence
This commit is contained in:
14
src/sequence/minByOrNull.ts
Normal file
14
src/sequence/minByOrNull.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export function minByOrNull<T>(value: Iterable<T>, transform: (it: T) => number): T | null {
|
||||
let minIt!: T;
|
||||
let min!: number;
|
||||
let found = false;
|
||||
for (const it of value) {
|
||||
const val = transform(it);
|
||||
if (found && val >= min) continue;
|
||||
minIt = it;
|
||||
min = val;
|
||||
found = true;
|
||||
}
|
||||
if (!found) return null;
|
||||
return minIt;
|
||||
}
|
||||
Reference in New Issue
Block a user