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

Function getCellAtIndex

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

Source from the content-addressed store, hash-verified

209 * @return {Cell}
210 */
211export const getCellAtIndex = (m, cellIndices) => {
212 // We start from the row at specific index.
213 let cell = m[cellIndices[0]];
214 // Going deeper into the next dimensions but not to the last one to preserve
215 // the pointer to the last dimension array.
216 for (let dimIdx = 1; dimIdx < cellIndices.length - 1; dimIdx += 1) {
217 cell = cell[cellIndices[dimIdx]];
218 }
219 // At this moment the cell variable points to the array at the last needed dimension.
220 return cell[cellIndices[cellIndices.length - 1]];
221};
222
223/**
224 * Update the matrix cell at specific index.

Callers 3

addFunction · 0.85
mulFunction · 0.85
subFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected