Skip to content

Instantly share code, notes, and snippets.

@uncompiled
Last active March 3, 2018 21:48
Show Gist options
  • Save uncompiled/2c7f37ae817dc7c0dad53e144bb14def to your computer and use it in GitHub Desktop.
Save uncompiled/2c7f37ae817dc7c0dad53e144bb14def to your computer and use it in GitHub Desktop.
Minify for loops
for (let i = 0; i < board.length; i++) {
returnBoard[i] = []
for (let j = 0; j < board[i].length; j++) {
let neighborCount = getCellNeighborCount(i, j)
if (board[i][j] === 1) {
if (neighborCount > 1 && neighborCount < 4) {
returnBoard[i][j] = 1
} else {
returnBoard[i][j] = 0
}
} else {
returnBoard[i][j] = neighborCount === 3 ? 1 : 0
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment