map
Produces a new array of values by mapping each value in the supplied array, collection or enumerable object through a transformation function.
Signature
map<T, R>(
list: TList<T> | undefined,
fn: (item: T, ...arguments: any[]) => R,
...arguments: any[]
): R[]
Parameters
Name | Type | Optional | Description |
---|---|---|---|
list | T[] | undefined | No | Specifies the array, collection or enumerable object to iterate through. |
fn | (...arguments: any[]) => T | void | No | Specifies the function to be invoked for each element. The element value will be exposed to the function as the first argument of the argument list. Additional arguments can be specified and will be pushed to the function. |
arguments | any[] | Yes | Optional arguments which should be passed to the callee. |
Return value
Returns an array with mapped values.
Example
import { map } from "@tripetto/runner";
map<number, number>([1, 2, 3], (nItem: number) => nItem * nItem); // Returns `[1, 4, 9]`
map<number, number>([1, 2, 3], (nItem: number, nMultiplier: number) => nItem * nMultiplier, 2); // Returns `[2, 4, 6]`