| 209 | * @return {Cell} |
| 210 | */ |
| 211 | export 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. |