(row, rows, col, cols)
| 33 | }; |
| 34 | |
| 35 | var getNeighbors = (row, rows, col, cols) => |
| 36 | [ |
| 37 | [0, 1], |
| 38 | [0, -1], |
| 39 | [1, 0], |
| 40 | [-1, 0], |
| 41 | ] |
| 42 | .map(([_row, _col]) => [row + _row, col + _col]) |
| 43 | .filter( |
| 44 | ([_row, _col]) => |
| 45 | 0 <= _row && _row < rows && 0 <= _col && _col < cols, |
| 46 | ); |
| 47 | |
| 48 | /** |
| 49 | * https://leetcode.com/problems/number-of-islands/ |