UNPKG

483 BJavaScriptView Raw
1import { identity } from '../util/identity';
2export function max(source, fn = identity) {
3 let atleastOnce = false;
4 let value = -Infinity;
5 for (const item of source) {
6 if (!atleastOnce) {
7 atleastOnce = true;
8 }
9 const x = fn(item);
10 if (x > value) {
11 value = x;
12 }
13 }
14 if (!atleastOnce) {
15 throw new Error('Sequence contains no elements');
16 }
17 return value;
18}
19
20//# sourceMappingURL=max.mjs.map