Skip to content

Instantly share code, notes, and snippets.

View uncompiled's full-sized avatar
🤠

Chris Nguyen uncompiled

🤠
View GitHub Profile
@uncompiled
uncompiled / for-loops.js
Last active March 3, 2018 21:48
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 {
@uncompiled
uncompiled / board.map.js
Last active March 3, 2018 22:16
Replace for loops with map
return board.map((row, x) =>
row.map((_, y) => {
let n = getCellNeighborCount(x, y)
return (isAlive(x, y) ? n > 1 && n < 4 : n === 3) ? 1 : 0
})
)
function gameOfLifeIterator(board) {
const isAlive = (x, y) => board[x] && board[x][y]
return board.map((row, x) =>
row.map((_, y) => {
let n = getCellNeighborCount(x, y)
return (isAlive(x, y) ? n > 1 && n < 4 : n === 3) ? 1 : 0
}))
function getCellNeighborCount (x, y) {
function gameOfLifeIterator(b) {
const a = (x, y) => b[x] && b[x][y]
return b.map((r, x) =>
r.map((_, y) => {
let n = 0
if (a(x - 1, y - 1)) n++
if (a(x - 1, y)) n++
if (a(x - 1, y + 1)) n++
if (a(x, y - 1)) n++
if (a(x, y + 1)) n++
function gameOfLifeIterator(b) {
const a = (x, y) => b[x] && b[x][y]
return b.map((r, x) =>
r.map((_, y) => {
let n = 0
a(x - 1, y - 1) && n++
a(x - 1, y) && n++
a(x - 1, y + 1) && n++
a(x, y - 1) && n++
a(x, y + 1) && n++
@uncompiled
uncompiled / empty.json
Created August 1, 2018 14:49
Empty JSON
{}

Keybase proof

I hereby claim:

  • I am uncompiled on github.
  • I am uncompiled (https://keybase.io/uncompiled) on keybase.
  • I have a public key ASDWgHhRDL5Jp-zAqlD-03CHp_wiod1ik17U_E-zq4xn5Ao

To claim this, I am signing this object: