Instead of using modular tricks, etc. use the X and Y coordinates and get a function to get the cell ID from the given X and Y , i.e.
function getCellId(x, y) { return 'cell-' + x + '-' + y); }
And name your cell id cell-0-0 → cell-9-9
Then neighboring cells
(x - 1, y - 1) (x, y - 1) (x + 1, y - 1) (x - 1, y ) (x + 1, y ) (x - 1, y + 1) (x, y + 1) (x + 1, y + 1)
This problem can also be resolved by using this approach.
source share