(visited, x, y)
| 75 | }; |
| 76 | |
| 77 | const getNeighbors = (visited, x, y) => { |
| 78 | const neighbors = []; |
| 79 | |
| 80 | if (y - 1 >= 0 && !visited[y - 1][x].closed) { |
| 81 | // left |
| 82 | neighbors.push(visited[y - 1][x]); |
| 83 | } |
| 84 | |
| 85 | if (y + 1 < visited[0].length && !visited[y + 1][x].closed) { |
| 86 | // right |
| 87 | neighbors.push(visited[y + 1][x]); |
| 88 | } |
| 89 | |
| 90 | if (x - 1 >= 0 && !visited[y][x - 1].closed) { |
| 91 | // up |
| 92 | neighbors.push(visited[y][x - 1]); |
| 93 | } |
| 94 | |
| 95 | if (x + 1 < visited.length && !visited[y][x + 1].closed) { |
| 96 | // down |
| 97 | neighbors.push(visited[y][x + 1]); |
| 98 | } |
| 99 | |
| 100 | return neighbors; |
| 101 | }; |
| 102 | |
| 103 | // unit tests |
| 104 | // do not modify the below code |
no test coverage detected