Is there a way to modify this function so that it only returns the neighbors directly above, below, left, and right instead of including corner neighbors?
function getNeighbors(nodes, column, row) {
var rowLimit = nodes.length - 1;
var columnLimit = nodes[0].length - 1;
for (let x = Math.max(0, column - 1); x <= Math.min(column + 1, columnLimit); x++) {
for (let y = Math.max(0, row - 1); y <= Math.min(row + 1, rowLimit); y++) {
if ((x === column && Math.abs(y - row) === 1) || (y === row && Math.abs(x - column) === 1)) {
board.nodes[column][row].neighbours.push(nodes[x][y]);
}
}
}
}