filter
Selects all items from an array, collection or enumerable object that match the truth function.
Signature
filter<T>(
list: TList<T> | undefined,
fn: (item: T) => boolean
): T[]
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 an array with the selected items.
Example
import { filter } from "@tripetto/runner";
filter<number>([1, 2, 3], (nItem: number) => nItem > 1); // Returns `[2, 3]`