Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda