sequency
Version:
Functional sequences for processing iterable data in JavaScript
32 lines • 973 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.Count = void 0;
var Count = /** @class */ (function () {
function Count() {
}
/**
* Returns the number of elements of this sequence. If `predicate` is present, returns
* the number of elements matching the given `predicate`.
*
* @param {(T) => boolean} predicate
* @returns {number}
*/
Count.prototype.count = function (predicate) {
var num = 0;
if (predicate == null) {
for (var item = this.iterator.next(); !item.done; item = this.iterator.next()) {
num++;
}
}
else {
for (var item = this.iterator.next(); !item.done; item = this.iterator.next()) {
if (predicate(item.value)) {
num++;
}
}
}
return num;
};
return Count;
}());
exports.Count = Count;
//# sourceMappingURL=count.js.map