I have been working on this too long now, so for some reason my sudoku validator keeps returning undefined, it has to be the sudokuisvalid part, but i have no clue why it wont return a boolean fixed the problem with the getRow, and the 1 where the I is supposed to be.
im really hoping its something obvious and im just too tired, and im new to programming so ill paste my code and see what y’all think!
function getRow(puzzle, row) {
// WRITE YOUR CODE HERE
return puzzle[row]
}
function getColumn(puzzle, col) {
// WRITE YOUR CODE HERE
return puzzle.map(row=>row[col])
}
function getSection(puzzle, x, y) {
// WRITE YOUR CODE HERE
let section = []
for(i = 3 * x; i < 3 * x + 3; i++){
for(j = 3 * y; j < 3*y+3 ; j++){
section.push(puzzle[i][j])
}
}
return section
}
function includes1To9(arr) {
// WRITE YOUR CODE HERE
for (i = 0; i < arr.length; i++){
for (j = 0; j < arr.length; j++){
if (j != i){
if (arr[i] === arr[j]){
return false
}
}
}
}
return true
}
function sudokuIsValid(puzzle) {
let valid =[]
for(let i=0; i<9; i++){
valid.push(getRow(puzzle,i))
valid.push(getColumn(puzzle, i))
}
for(let i=0; i<3; i++){
for(let j=0; j<3; j++){
valid.push(getSection(puzzle, i, j))
}
}
for(let i= 0; i< valid.length; i++){
if(includes1To9(valid[i] === false)){
return false
}
}
return true
}