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

Function walk

src/algorithms/math/matrix/Matrix.js:180–202  ·  view source on GitHub ↗
(m, visit)

Source from the content-addressed store, hash-verified

178 * @param {function(indices: CellIndices, c: Cell)} visit
179 */
180export const walk = (m, visit) => {
181 /**
182 * Traverses the matrix recursively.
183 *
184 * @param {Matrix} recM
185 * @param {CellIndices} cellIndices
186 * @return {Matrix}
187 */
188 const recWalk = (recM, cellIndices) => {
189 const recMShape = shape(recM);
190
191 if (recMShape.length === 1) {
192 for (let i = 0; i < recM.length; i += 1) {
193 visit([...cellIndices, i], recM[i]);
194 }
195 }
196 for (let i = 0; i < recM.length; i += 1) {
197 recWalk(recM[i], [...cellIndices, i]);
198 }
199 };
200
201 recWalk(m, []);
202};
203
204/**
205 * Gets the matrix cell value at specific index.

Callers 3

addFunction · 0.85
mulFunction · 0.85
subFunction · 0.85

Calls 1

recWalkFunction · 0.85

Tested by

no test coverage detected