UNPKG

iteragain

Version:

Javascript Iterable/Iterator/Generator-function utilities.

28 lines 1.14 kB
import { MINMAX_EMPTY_ERROR } from './internal/emptyIteratorError'; import toIterator from './toIterator'; export function minmax() { var _a; var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } if (!args.length || typeof args[0] === 'function') return function (it) { return minmax(it, args[0]); }; var it = toIterator(args[0]); var iteratee = (_a = args[1]) !== null && _a !== void 0 ? _a : (function (x) { return x; }); var next = it.next(); if (next.done) throw new TypeError(MINMAX_EMPTY_ERROR); var min = { value: next.value, comparison: iteratee(next.value) }; var max = { value: next.value, comparison: iteratee(next.value) }; while (!(next = it.next()).done) { var comparison = iteratee(next.value); if (comparison < min.comparison) min = { value: next.value, comparison: comparison }; if (comparison > max.comparison) max = { value: next.value, comparison: comparison }; } return [min.value, max.value]; } export default minmax; //# sourceMappingURL=minmax.js.map