(
matrix,
row,
col,
direction,
changeDirection,
order,
VISITED = 101,
)
| 262 | }; |
| 263 | |
| 264 | const move = ( |
| 265 | matrix, |
| 266 | row, |
| 267 | col, |
| 268 | direction, |
| 269 | changeDirection, |
| 270 | order, |
| 271 | VISITED = 101, |
| 272 | ) => { |
| 273 | const [rows, cols] = [matrix.length, matrix[0].length]; |
| 274 | |
| 275 | while (canMove(matrix, row, rows, col, cols, direction)) { |
| 276 | /* Time O(ROWS * COLS) */ |
| 277 | [row, col] = getCell(row, col, direction); |
| 278 | |
| 279 | order.push( |
| 280 | matrix[row][col], |
| 281 | ); /* | Ignore Auxilary Spsace O(ROWS * COLS) */ |
| 282 | matrix[row][col] = VISITED; |
| 283 | |
| 284 | changeDirection = 0; |
| 285 | } |
| 286 | |
| 287 | return [row, col, direction, changeDirection]; |
| 288 | }; |
| 289 | |
| 290 | const canMove = (matrix, row, rows, col, cols, direction) => { |
| 291 | if (!isInBounds(row, rows, col, cols, direction)) return false; |
no test coverage detected