Skip to content

Latest commit

 

History

History
69 lines (35 loc) · 1.12 KB

File metadata and controls

69 lines (35 loc) · 1.12 KB

Home > @josh-brown/vector > Vector > map

Vector.map() method

Constructs a vector by transforming the values of another vector.

Signature:

map(valueFromEntry: (entry: S, index: number) => S): Vector<S>;

Parameters

Parameter

Type

Description

valueFromEntry

(entry: S, index: number) => S

A function which takes an entry of the original vector and its index, and returns the corresponding entry of the new vector

Returns:

Vector<S>

The new vector

Example

const original = vectorBuilder.fromValues(1, 2, 3, 4);

const originalPlusOne = original.map(value => value + 1);
// [2, 3, 4, 5]

const originalPlusIndex = original.map((value, index) => value + index);
// [1, 3, 5, 7]