2021年5月4日星期二

Find and count adjacent array's elements in a 2D array in javascript

so im working on a function or a solution for this problem but im still a junior. this is the provided array, [javascript] **

```[    [0, 9, 0, 0],    [0, 0, 9, 0],    [0, 9, 0, 9],    [9, 9, 0, 0],    ]  

**

im starting a minesweeper project, the zeros are empty spaces , the 9's are mines, i need to change the zeros to the number of adjacent mines, i couldnt find a simple solution that i could understand , so if someone can provide a simple solution i would appreciate it.  i thought about getting the  coordinates   ```[x-1][y-1], [x][y-1] [x] [y+1] ```   etc.. for each index but the thing is not every index has these coordinates. help plz  
https://stackoverflow.com/questions/67394288/find-and-count-adjacent-arrays-elements-in-a-2d-array-in-javascript May 05, 2021 at 10:07AM

没有评论:

发表评论