@kingjs/linq.count

1.0.6 • Public • Published

@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

Readme

Keywords

none

Package Sidebar

Install

npm i @kingjs/linq.count

Weekly Downloads

0

Version

1.0.6

License

MIT

Unpacked Size

3.45 kB

Total Files

4

Last publish

Collaborators

  • kingces95