Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
Why is the i variable in my for loop not changing

It's probably just a small mistake, but I can't figure it out. I'm making a program to check if a sudoku has multiple solutions but the variable i in my for loop doesn't transfer to the solve function.

When I call the solve function with a hardcoded number then it works as expected. But if not then it uses the value i is initialized to and doesn't change.

function unique(bo) {
    let boards = []
    let i = 0
    for (i = 0; i <= bo.length; i++) {
        let num = i
        console.log(num) //returns i correctly
        let board = []
        board = solve(bo, num) //num is not updated

        if (board) {
            boards.push(board)
        }
    }
    if (new Set(boards).size === 1) {
        return true
    } else {
        return false
    }
}

function solve(bo, st) {
    let numberList = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    numberList = Rotate(numberList, parseInt(st))
    let found = findEmpty(bo)

    if (!validateBoard(bo)) {
        return false
    }

    let row, col;
    //any more left?
    if (!found) {
        return bo
    }

    [row, col] = found
    //return bo
    for (let i = 0; i < numberList.length; i++) {
        if (validate(bo, numberList[i], [row, col])) {
            bo[row][col] = numberList[i];
            solve(bo, st)
        }
    }

    if (findEmpty(bo)) {
        bo[row][col] = 0;
    }
    return bo
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!