Sudoo-Matrix
support add operation. Add operation only can process a matrix with the same size.
For matrix typed with string
or number
, add operation can be run at the default setting.
import { matrixAdd, Matrix } from "@sudoo/matrix";
const result: Matrix<number> = matrixAdd(
[
[1, 1],
[1, 1],
],
[
[1, 2],
[3, 4],
],
);
The result
variable type for the above code is
[
[2, 3],
[4, 5],
]
For matrix type other than string
or number
, add operation much run with an override add function.
import { matrixAdd, Matrix } from "@sudoo/matrix";
const result: Matrix<number> = matrixAdd(
[
[true, true],
[true, true],
],
[
[true, false],
[true, false],
],
(a: boolean, b: boolean) => {
return Number(a) + Number(b);
},
);
The result
variable type for the above code is
[
[2, 1],
[2, 1],
]