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

170
Visualizações
how to fix the corner problem in a minesweeper?

I'm coding the reveal function trying to use recursion but I have a problem, when the cycle runs at the corner it doesn't find any cell and returns an error, I've seen that this operator '?.' returns the value or undefined even if there is no value, but I cant figure how this operator could be included in my cycle

export function reveal(boardWithMines: CellEnum[][], boardWithOutMines: CellEnum[][], x: number, y: number) {  
    if (boardWithOutMines[x][y] === CellEnum.Hidden || boardWithMines[x][y] === CellEnum.Cero) {
        boardWithOutMines[x][y] = boardWithMines[x][y];
        for (let xOffset = -1; xOffset <= 1; xOffset++) {
            for (let yOffset = -1; yOffset <= 1; yOffset++) {
                reveal(boardWithMines, boardWithOutMines, x + xOffset, y + yOffset);
            }
        }
    }
}

This is the error that shows up in the console

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Check the bounds in the loops:

export function reveal(boardWithMines: CellEnum[][], boardWithOutMines: CellEnum[][], x: number, y: number) {  
    if (boardWithOutMines[x][y] === CellEnum.Hidden || boardWithMines[x][y] === CellEnum.Cero) {
        boardWithOutMines[x][y] = boardWithMines[x][y];
        for (let i = Math.max(0, x-1), iMax = Math.min(boardWithMines.length, x+2); i < iMax; ++i) {
            for (let j = Math.max(0, y-1), jMax = Math.min(boardWithMines[i].length, y+2); j < jMax; ++j) {
                reveal(boardWithMines, boardWithOutMines, i, j);
            }
        }
    }
}
about 4 years ago · Juan Pablo Isaza Relatório
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