@kingjs/linq.last

Returns the last element of a sequence that satisfies a specified condition.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
@kingjs/linq.last
081.0.74 years ago4 years agoMinified + gzip package size for @kingjs/linq.last in KB

Readme

@kingjs/linq.last
Returns the last element of a sequence that satisfies a specified condition.

Usage

Return the last value of 0, 1, 2 like this; ```js var lastOrUndefined = require('@kingjs/linq.last'); var sequence = require('@kingjs/enumerable.create'); lastOrUndefined.call(sequence(0, 1, 2)); ``` result: ```js 2 ``` Return the last odd value of 0, 1, 2, 3, 4 like this; ```js var lastOrUndefined = require('@kingjs/linq.last'); var sequence = require('@kingjs/enumerable.create'); var isOdd = function(x) { return x % 2 == 1; } lastOrUndefined.call(sequence(0, 1, 2, 3, 4), isOdd); ``` result: ```js 3 ```

API

```ts declare function last( this: Enumerable, predicate?: (x) => boolean ) ```

Interfaces

Parameters

  • this: The sequence of which last element is returned.
  • predicate: Optional predicate element must satisfy.

Return Value

Last element in the sequence or throw if sequence is empty. If a predicate is provided, then the last element to match the predicate else throw if no element satisfies the predicate.

Install

With npm installed, run ``` $ npm install @kingjs/linq.last ```

Acknowledgments

Like Enumerable.Last.aspx).

License

MIT Analytics