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

169
Views
¿Cómo solucionar el problema de la esquina en un buscaminas?

Estoy codificando la función de revelación tratando de usar la recursividad pero tengo un problema, cuando el ciclo se ejecuta en la esquina no encuentra ninguna celda y devuelve un error, he visto que este operador '?' devuelve el valor o indefinido incluso si no hay valor, pero no puedo entender cómo podría incluirse este operador en mi ciclo

 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); } } } }

Este es el error que aparece en la consola.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Compruebe los límites en los bucles:

 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 Report
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!