This commit is contained in:
11
src/collection/maxWith.ts
Normal file
11
src/collection/maxWith.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user