@newdash/newdash
Version:
javascript/typescript utility library
33 lines (32 loc) • 1.19 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.baseExtremum = void 0;
const isSymbol_1 = __importDefault(require("../isSymbol"));
/**
* The base implementation of methods like `max` and `min` which accepts a
* `comparator` to determine the extremum value.
*
* @private
* @ignore
* @param array The array to iterate over.
* @param iteratee The iteratee invoked per iteration.
* @param comparator The comparator used to compare values.
* @returns Returns the extremum value.
*/
function baseExtremum(array, iteratee, comparator) {
var index = -1, length = array.length;
while (++index < length) {
var value = array[index], current = iteratee(value);
if (current != null && (computed === undefined
? (current === current && !(0, isSymbol_1.default)(current))
: comparator(current, computed))) {
var computed = current, result = value;
}
}
return result;
}
exports.baseExtremum = baseExtremum;
exports.default = baseExtremum;