| 178 | * @param {function(indices: CellIndices, c: Cell)} visit |
| 179 | */ |
| 180 | export 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. |