Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Simple & Clear & Readable solution in Clear category for [old] Moore Neighbourhood by Rool_Kach
function countNeighbours(data, row, col) {
let neighbours = 0;
[-1,0,1].forEach(dr => [-1,0,1]
.forEach(dc => neighbours += (dr || dc)
&& data[dr+row]
&& data[dr+row][dc+col]
|| 0));
return neighbours;
}
Jan. 25, 2019