1.0.8 • Published 7 years ago
@kingjs/linq.last-or-undefined v1.0.8
@kingjs/linq.last-or-undefined
Returns the last element of a sequence that satisfies a specified condition or a undefined.
Usage
Return the last value of 0, 1, 2 like this;
var lastOrUndefined = require('@kingjs/linq.last-or-undefined');
var sequence = require('@kingjs/enumerable.create');
lastOrUndefined.call(sequence(0, 1, 2));result:
2Return the last odd value of 0, 1, 2, 3, 4 like this;
var lastOrUndefined = require('@kingjs/linq.last-or-undefined');
var sequence = require('@kingjs/enumerable.create');
var isOdd = function(x) { return x % 2 == 1; }
lastOrUndefined.call(sequence(0, 1, 2, 3, 4), isOdd);result:
3API
declare function lastOrUndefined(
this: Enumerable,
predicate?: (x) => boolean
)Interfaces
Enumerable: See @kingjs/enumerable.define.
Parameters
this: The sequence of which last element is returned.predicate: Optional predicate element must satisfy.
Return Value
Last element in the sequence or undefined if sequence is empty. If a predicate is provided, then the last element to match the predicate else undefined if no element satisfies the predicate.
Install
With npm installed, run
$ npm install @kingjs/linq.last-or-undefinedAcknowledgments
Like Enumerable.LastOrDefault.
License
MIT