kingjs/linq.count
@Returns the number of elements in a sequence that satisfy a condition.
Usage
Count the number of elements in sequence 1
, 2
, 3
like this:
var count = require('@kingjs/linq.count');
var sequence = require('@kingjs/enumerable.create');
count.call(sequence(1, 2, 3));
result:
3
Count the number of odd numbers in sequence 1
, 2
, 3
like this:
var count = require('@kingjs/linq.count');
var sequence = require('@kingjs/enumerable.create');
var isOdd = function(o) { return o % 2 == 1; }
count.call(sequence(1, 2, 3), isOdd);
result:
2
API
declare function count(
this: Enumerable,
predicate?: (x) => boolean
): number
Interfaces
-
Enumerable
: See @kingjs/enumerable.define.
Parameters
-
this
: The sequence to count values matching predicate. -
predicate
: To be counted, values must match this predicate.
Return Value
Returns the number of values that satisfy the predicate.
Remarks
By default, the predicate is satisfied by any value.
Install
With npm installed, run
$ npm install @kingjs/linq.count
Acknowledgments
Like Enumerable.Count
.
License
MIT