I have a bulk operation that operates on a 2 dimensional array. It shall call a given method "func" on each element in the array:
function forEachMatrixElement(matrix: Complex[][], func: Function): Complex[][] {
let matrixResult: Complex[][] = new Array(countRows(matrix)).fill(false).map(() => new Array(countCols(matrix)).fill(false)); // Creates a result 2D-Matrix
for (let row = 0; row < countRows(matrix); row++) {
for (let col = 0; col < countCols(matrix); col++) {
matrixResult[row][col] = func.call(matrix[row][col]); // Call the given method
}
}
return matrixResult;
}
I have two functions that I want to delegate to this method: This one takes no additional arguments and works fine:
export function conjugateMatrix(matrix: Complex[][]): Complex[][] {
return forEachMatrixElement(matrix, Complex.prototype.conjugate);
}
This one takes an additional argument (a scalar). But I don't know how to add this argument to this method reference on the prototype:
export function multiplyMatrixScalar(matrix: Complex[][], scalar: Complex): Complex[][] {
return forEachMatrixElement(matrix, Complex.prototype.mul); // TODO Call with scalar
}