Created
March 3, 2018 21:40
-
-
Save uncompiled/2352a07f69650f7509a8474b86f21b90 to your computer and use it in GitHub Desktop.
Refactor getCellNeighborCount
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getCellNeighborCount (x, y, board) { | |
let neighborCount = 0 | |
if (isAlive(x - 1, y - 1)) neighborCount++ | |
if (isAlive(x - 1, y)) neighborCount++ | |
if (isAlive(x - 1, y + 1)) neighborCount++ | |
if (isAlive(x, y - 1)) neighborCount++ | |
if (isAlive(x, y + 1)) neighborCount++ | |
if (isAlive(x + 1, y - 1)) neighborCount++ | |
if (isAlive(x + 1, y)) neighborCount++ | |
if (isAlive(x + 1, y + 1)) neighborCount++ | |
return neighborCount | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment