sequency
Version:
Functional sequences for processing iterable data in JavaScript
28 lines • 915 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.MaxBy = void 0;
var MaxBy = /** @class */ (function () {
function MaxBy() {
}
/**
* Returns the maximum element by comparing the results of the given `selector` function
* for each element of the sequence or `null` if the sequence is empty.
*
* @param {(value: T) => R} selector
* @returns {T}
*/
MaxBy.prototype.maxBy = function (selector) {
var max = null;
var maxSelected = null;
for (var item = this.iterator.next(); !item.done; item = this.iterator.next()) {
var value = selector(item.value);
if (maxSelected == null || value > maxSelected) {
maxSelected = value;
max = item.value;
}
}
return max;
};
return MaxBy;
}());
exports.MaxBy = MaxBy;
//# sourceMappingURL=maxBy.js.map