@kingjs/linq.contains

Returns true if a sequence contains a specified element.

Stats

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

Readme

@kingjs/linq.contains

Returns true if a sequence contains a specified element.

Usage

Discover if the sequence 1, 2, 3 contains the value 2 like this:

var contains = require('@kingjs/linq.contains');
var sequence = require('@kingjs/enumerable.create');

contains.call(sequence(1, 2, 3), 2);

result:

true

Discover if 'Chris' is contained in a list of people like this:

var contains = require('@kingjs/linq.contains');
var sequence = require('@kingjs/enumerable.create');

var people = sequence(
  { name: 'Alice' },
  { name: 'Bob' },
  { name: 'Chris' },
);

var equal = function(l, r) { 
  return l.name == r.name; 
}

contains.call(people, { name: 'Chris' }, equal);

result:

true

API

declare function contains(
  this: Enumerable,
  target: any,
  equal?: (left, right) => boolean
): boolean

Interfaces

Parameters

  • this: The sequence to search.
  • target: The value to find.
  • equal: Optional comparison operator.

Return Value

Returns true if target is present, false otherwise.

Remarks

By default, the comparison operator is Javascript's == operator.

Install

With npm installed, run

$ npm install @kingjs/linq.contains

Acknowledgments

Like Enumerable.Contains.

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.