Home > @josh-brown/vector > Matrix > map
Builds a matrix by transforming the values of the current matrix.
Signature:
map(entryFunction: (entry: S, rowIndex: number, columnIndex: number) => S): Matrix<S>;|
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
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 ]