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.