Skip to content

Instantly share code, notes, and snippets.

@uncompiled
Created March 3, 2018 21:40
Show Gist options
  • Save uncompiled/2352a07f69650f7509a8474b86f21b90 to your computer and use it in GitHub Desktop.
Save uncompiled/2352a07f69650f7509a8474b86f21b90 to your computer and use it in GitHub Desktop.
Refactor getCellNeighborCount
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