12 lines
278 B
TypeScript
12 lines
278 B
TypeScript
export function maxOrNull(value: Iterable<number>): number | null {
|
|
let max!: number;
|
|
let found = false;
|
|
for (const it of value) {
|
|
if (found && it <= max) continue;
|
|
max = it;
|
|
found = true;
|
|
}
|
|
if (!found) return null;
|
|
return max;
|
|
}
|