iteragain
Version:
Javascript Iterable/Iterator/Generator-function utilities.
18 lines • 667 B
JavaScript
import toIterator from './toIterator';
export function max(...args) {
var _a;
if (!args.length || typeof args[0] === 'function')
return (it) => max(it, args[0]);
const it = toIterator(args[0]);
const iteratee = (_a = args[1]) !== null && _a !== void 0 ? _a : ((x) => x);
let next = it.next();
let result = { value: next.value, comparison: iteratee(next.value) };
while (!(next = it.next()).done) {
const comparison = iteratee(next.value);
if (comparison > result.comparison)
result = { value: next.value, comparison };
}
return result.value;
}
export default max;
//# sourceMappingURL=max.js.map