findLast
Selects the last item from an array, collection or enumerable object that matches the truth function.
Signature
findLast<T>(
list: TList<T> | undefined,
fn: (item: T) => boolean
): T | undefined
Parameters
Name | Type | Optional | Description |
---|---|---|---|
list | T[] | undefined | No | Specifies the array, collection or enumerable object to iterate through. |
fn | (item: T) => boolean | No | Specifies the truth function. Each item is supplied to the function, passing the item as argument. The function should return a boolean value whether to include the item in the selection. |
Return value
Returns the item or undefined
if no item is found.
Example
import { findLast } from "@tripetto/builder";
findLast<number>([1, 2, 3], (nItem: number) => nItem > 1); // Returns `3`