MCPcopy
hub / github.com/trekhleb/javascript-algorithms / updateCellAtIndex

Function updateCellAtIndex

src/algorithms/math/matrix/Matrix.js:230–240  ·  view source on GitHub ↗
(m, cellIndices, cellValue)

Source from the content-addressed store, hash-verified

228 * @param {Cell} cellValue - New cell value
229 */
230export const updateCellAtIndex = (m, cellIndices, cellValue) => {
231 // We start from the row at specific index.
232 let cell = m[cellIndices[0]];
233 // Going deeper into the next dimensions but not to the last one to preserve
234 // the pointer to the last dimension array.
235 for (let dimIdx = 1; dimIdx < cellIndices.length - 1; dimIdx += 1) {
236 cell = cell[cellIndices[dimIdx]];
237 }
238 // At this moment the cell variable points to the array at the last needed dimension.
239 cell[cellIndices[cellIndices.length - 1]] = cellValue;
240};
241
242/**
243 * Adds two matrices element-wise.

Callers 3

addFunction · 0.85
mulFunction · 0.85
subFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected