Skip to content

Instantly share code, notes, and snippets.

View uncompiled's full-sized avatar
🤠

Chris Nguyen uncompiled

🤠
View GitHub Profile

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:

@uncompiled
uncompiled / empty.json
Created August 1, 2018 14:49
Empty JSON
{}
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++
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(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) {
@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
})
)
@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 / getCellNeighborCount.js
Created March 3, 2018 21:40
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++
@uncompiled
uncompiled / gameOfLife.js
Created March 3, 2018 21:00
Starting Point for Conway's Game of Life
function gameOfLifeIterator(board) {
let returnBoard = [];
for (let i = 0; i < board.length; i++) {
returnBoard[i] = [];
for (let j = 0; j < board[i].length; j++) {
let neighborCount = getCellNeighborCount(i, j, board);
if (board[i][j] === 1) {
@uncompiled
uncompiled / commented.js
Last active February 4, 2018 20:09
All Tests Pass Week 3: Manual Minification
// This file includes the reasoning behind my manual minification choices.
// I wouldn't write code like this for an actual project because if I
// looked at this code in 2 months, I'd probably say WTF.
function largestCommonSubstring(a, b) {
// Use one declaration to minimize the number of let statements
let l = 0, // Length of the longest common substring
s = '', // Substring to return
// Generate mxn array filled with zeroes
// I would probably call this "lcs" in a real project,