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

160
Views
Change matrix edge elements

I have a squared matrix with all the values that are equal to zero. I pass this matrix to a function. Then I want all the element that are in the edges changes to one. Like from this

000    111
000 -->101
000    111

Here is the code that should work:

function putWalls(maze){
    //outside wall
    for(let i=0; i<maze.length;i++){
        for(let j=0;j<maze.length;j++){
            if(i==0 || i==maze.length-1 || j==0 || j==maze.length-1){
                maze[i][j] = 1;
            }
        }
    }
    return maze;
}

But it returns all the matrix full of 1, and I can't understand why. Probably is a stupid error. If I print out inside the if the combination, it shows the comìbination I want, but it changes everything.

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!