I have a couple of functions that loop around the surrounding cells of a cell. The grid is contained inside an array.
In my code, I have checks to make sure it's not one of the edge cells, as checking an undefined cell causes an error.
As such, I have code like this:
if(x > 0) {
var firstX = x - 1;
} else {
var firstX = x;
}
if(x < 199) {
var lastX = x + 1;
} else {
var lastX = x;
}
if(y > 0) {
var firstY = y - 1;
} else {
var firstY = y;
}
if(y < 199) {
var lastY = y + 1;
} else {
var lastY = y;
}
A lot of lines of code to do very little. Is there a more elegant way to do this?