(matrix, row, col)
| 121 | } |
| 122 | |
| 123 | function getNeighbors(matrix, row, col) { |
| 124 | const neighbors = []; |
| 125 | |
| 126 | const numRows = matrix.length; |
| 127 | const numCols = matrix[row].length; |
| 128 | |
| 129 | if (row - 1 >= 0) neighbors.push([row - 1, col]); //UP |
| 130 | if (row + 1 < numRows) neighbors.push([row + 1, col]); //DOWN |
| 131 | if (col - 1 >= 0) neighbors.push([row, col - 1]); //LEFT |
| 132 | if (col + 1 < numCols) neighbors.push([row, col + 1]); //RIGHT |
| 133 | |
| 134 | return neighbors; |
| 135 | } |
| 136 | |
| 137 | const input = [ |
| 138 | [1, 0, 0, 0, 0, 0], |
no test coverage detected