deno.land / x / masx200_leetcode_test@10.6.5 / minesweeper / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
export default function updateBoard( board: string[][], click: number[],): string[][] { const [row, col] = click; if (board[row][col] === "M") { board[row][col] = "X"; return board; } if (board[row][col] === "E") { const validpos = dirs.map((v) => [row + v[0], col + v[1]]).filter((v) => typeof board[v[0]]?.[v[1]] !== "undefined" ); const count = validpos.reduce( (a, v) => a + Number(["X", "M"].includes(board[v[0]][v[1]])), 0, ); if ( count > 0 ) board[row][col] = String(count); else { board[row][col] = "B"; return validpos.reduce( (b, v) => updateBoard(b, [v[0], v[1]]), board, ); } return board; } return board;}const dirs = [[0, 1], [1, 0], [0, -1], [-1, 0], [1, 1], [1, -1], [-1, 1], [ -1, -1,]];
masx200_leetcode_test

Version Info

Tagged at
a year ago