https://leetcode.com/problems/game-of-life/


Runtime: 119 ms, faster than 8.94% of TypeScript online submissions for Game of Life.

Memory Usage: 45.7 MB, less than 5.11% of TypeScript online submissions for Game of Life.


```typescript
/**
 Do not return anything, modify board in-place instead.
 */
function gameOfLife(board: number[][]): void {
    //10:45
    const inRange = (x: number, y: number) => {
        if ((y >= board.length) || (y<0)) {
            return false
        }
        if ((x >= board[0].length) || (x<0)) {
            return false
        }
        return true
    }
    
    const dieOrLive = (x: number, y: number) => {
        let checkList = []
        let temp_x = x - 1
        let temp_y = y - 1
        let temp_x2 = x + 2
        let temp_y2 = y + 2
        while (temp_y < temp_y2) {
            while (temp_x < temp_x2) {
                //console.log("hi: ", temp_x, temp_y)
                if (inRange(temp_x, temp_y)) {
                    checkList.push(board[temp_y][temp_x])
                }
                temp_x += 1
            }
            temp_y += 1
            temp_x = x - 1
        }
        
        let around_lives = checkList.filter((thex: number)=>{return thex==1}).length
        let current = board[y][x]
        if (current == 1) {
            around_lives -= 1
        }
        //console.log([x,y], checkList, around_lives)
        
        if (current == 1) {
            if (around_lives < 2) {
                return 0
            }
            if ((around_lives == 2) || (around_lives == 3)) {
                return 1
            }
            if (around_lives > 3) {
                return 0
            }
        }
        if (current == 0) {
            if (around_lives == 3) {
                return 1
            }
        }
        
        return current
    }
    
    const newBoard = JSON.parse(JSON.stringify(board));
    for (const [y, row] of board.entries()) {
        for (const [x, value] of row.entries()) {
            newBoard[y][x] = dieOrLive(x, y)
        }
    }

    for (const [y, row] of newBoard.entries()) {
        for (const [x, value] of row.entries()) {
            board[y][x] = value
        }
    }

    //11:08
    //debug until 12:05
};
```
