Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions Backtracking/NQueens.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
class NQueens {
constructor(size) {
if (size < 0) {
throw RangeError('Invalid board size')
if (size <= 0) {
throw RangeError('Board size must be a positive integer')
}

this.board = new Array(size).fill('.').map(() => new Array(size).fill('.'))
this.size = size
this.solutionCount = 0
Expand Down Expand Up @@ -40,7 +41,7 @@ class NQueens {
solve(col = 0) {
if (col >= this.size) {
this.solutionCount++
return true
return
}

for (let i = 0; i < this.size; i++) {
Expand All @@ -50,8 +51,6 @@ class NQueens {
this.removeQueen(i, col)
}
}

return false
}

printBoard(output = (value) => console.log(value)) {
Expand Down