Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Clear category for [old] Moore Neighbourhood by Moff
function countNeighbours(data, row, col) {
let delta = [[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1]];
let result = 0;
delta.forEach(([r, c]) => {
result += (data[row + r] || [])[col + c] || 0;
});
return result;
}
July 10, 2017
Comments: