Its basically an out of bounds check, tho' I'm having issues understanding how to deal with undefined values in a 2d array.
What I've tried so far is checking if both the column and the row index exist if(!arr[x][y]), checking if both are undefined if(arr[x][y] === undefined) and finally checking if the indexes are bigger then the array length - 1 ( the array is 10x10 ).
None of the above have worked, even when putting the conditions togheter I still get
TypeError: Cannot set property '' of undefined.
Is there a way to deal with this ?
Edit:
The TypeError appears at if (arr[x + i * dx][y + i * dy] === undefined) more precisely at [y + i * dy] where x and y are the column and row indexes, dx and dy are either 0 or 1 values so it can check either vertically or horizontally.
If I check vertically, I dont get any errors, its only when I check horizontally that I encounter the TypeError.