Skip to content

Latest commit

 

History

History
76 lines (40 loc) · 1.22 KB

File metadata and controls

76 lines (40 loc) · 1.22 KB

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

Matrix.map() method

Builds a matrix by transforming the values of the current matrix.

Signature:

map(entryFunction: (entry: S, rowIndex: number, columnIndex: number) => S): Matrix<S>;

Parameters

Parameter

Type

Description

entryFunction

(entry: S, rowIndex: number, columnIndex: number) => S

A function which takes an entry of the original matrix and its indices, and returns the corresponding entry of the new matrix

Returns:

Matrix<S>

The new matrix

Example

const original = matrixBuilder.fromArray([
  [ 1, 2, 3 ]
  [ 4, 5, 6 ]
]);

const originalPlusOne = original.map(value => value + 1);

// [ 2 3 4 ]
// [ 5 6 7 ]

const originalPlusIMinusJ = original.map((value, i, j) => value + i - j);

// [ 1 1 1 ]
// [ 5 5 5 ]