()
| 39 | } |
| 40 | |
| 41 | solve() { |
| 42 | const [y, x] = this.findEmptyCell() |
| 43 | |
| 44 | // checking if the board is complete |
| 45 | if (y === -1 && x === -1) return true |
| 46 | |
| 47 | for (let val = 1; val < 10; val++) { |
| 48 | if (this.check([y, x], val)) { |
| 49 | this.board[y][x] = val |
| 50 | if (this.solve()) return true |
| 51 | // backtracking if the board cannot be solved using current configuration |
| 52 | this.board[y][x] = 0 |
| 53 | } |
| 54 | } |
| 55 | // returning false the board cannot be solved using current configuration |
| 56 | return false |
| 57 | } |
| 58 | |
| 59 | getSection(row, [start, end]) { |
| 60 | return this.board[row].slice(start, end) |
no test coverage detected