@kingjs/linq.count

Returns the number of elements in a sequence that satisfy a condition.

Stats

StarsIssuesVersionUpdatedCreatedSize
@kingjs/linq.count
1.0.63 years ago3 years agoMinified + gzip package size for @kingjs/linq.count in KB

Readme

@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

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

Analytics

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.