sequency
Version:
Functional sequences for processing iterable data in JavaScript
28 lines • 915 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.MinBy = void 0;
var MinBy = /** @class */ (function () {
function MinBy() {
}
/**
* Returns the minimum 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}
*/
MinBy.prototype.minBy = function (selector) {
var min = null;
var minSelected = null;
for (var item = this.iterator.next(); !item.done; item = this.iterator.next()) {
var value = selector(item.value);
if (minSelected == null || value < minSelected) {
minSelected = value;
min = item.value;
}
}
return min;
};
return MinBy;
}());
exports.MinBy = MinBy;
//# sourceMappingURL=minBy.js.map