Currently, I am working on the reveal function using recursion in my coding project. However, I have encountered an issue where the cycle is unable to find any cell when it reaches the corner, resulting in an error. I have come across the '?.' operator, which returns a value or undefined even if there is no actual value present. I'm struggling to understand how I can incorporate this operator into 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);
}
}
}
}
I am encountering this specific error message in the console window