nextGeneration () {
    this.originalAliveCoords = this.clone(this.board.aliveCoords)
    this.alive = 0

    let allDeadNeighbours = {}

    // Loop through alive coords.
    for (let y in this.board.aliveCoords) {
      // Get hash of all x coords with the same y coord.
      y = parseInt(y, 10)
      let xHash = this.board.aliveCoords[y]

      for (let x in xHash) {
        x = parseInt(x, 10)
        let neighbourCoords = this.getNeighbourCoords(x, y)

        let aliveNeighbourCount = this.getAliveNeighbourCount(x, y, neighbourCoords)

        // Under-population or overcrowding...
        if (aliveNeighbourCount < 2 || aliveNeighbourCount > 3) {
          this.removeFromAliveCoords(x, y, this.board.aliveCoords)
        } else {
          this.alive++
        }

        // Keep count of dead neighbours.
        for (let n = 0; n < neighbourCoords.length; n++) {
          let [x, y] = neighbourCoords[n]

          if (x >= this.board.numcols || x < 0) continue
          if (y >= this.board.numrows || y < 0) continue

          if (!this.isCellAlive(x, y, this.originalAliveCoords)) {
            let key = x + ',' + y

            if (allDeadNeighbours[key] === undefined) {
              allDeadNeighbours[key] = 0
            }

            allDeadNeighbours[key]++
          }
        }
      }
    }

    // Check for reproduction case.
    for (let key in allDeadNeighbours) {
      if (allDeadNeighbours[key] === 3) {
        let coords = key.split(',')
        let [x, y] = [parseInt(coords[0], 10), parseInt(coords[1], 10)]

        this.addToAliveCoords(x, y, this.board.aliveCoords)
        this.alive++
      }
    }
  }
/**
   * Rules:
   * 1) Any live cell with fewer than two live neighbours dies, as if caused by under-population.
   * 2) Any live cell with two or three live neighbours lives on to the next generation.
   * 3) Any live cell with more than three live neighbours dies, as if by overcrowding.
   * 4) Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
   */
1) Any live cell with fewer than two live neighbours dies, as if caused by under-population.
2) Any live cell with two or three live neighbours lives on to the next generation.
3) Any live cell with more than three live neighbours dies, as if by overcrowding.
4) Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
1 ) Any live cell with fewer than two live neighbours dies as if caused by under - population . 2 ) Any live cell with two or three live neighbours lives on to the next generation . 3 ) Any live cell with more than three live neighbours dies as if by overcrowding . 4 ) Any dead cell with exactly three live neighbours becomes a live cell as if by reproduction .
nextGeneration () {
    this.originalAliveCoords = this.clone(this.board.aliveCoords)
    this.alive = 0
    let allDeadNeighbours = {}
    for (let y in this.board.aliveCoords) {
      y = parseInt(y, 10)
      let xHash = this.board.aliveCoords[y]
      for (let x in xHash) {
        x = parseInt(x, 10)
        let neighbourCoords = this.getNeighbourCoords(x, y)
        let aliveNeighbourCount = this.getAliveNeighbourCount(x, y, neighbourCoords)
        if (aliveNeighbourCount < 2 || aliveNeighbourCount > 3) {
          this.removeFromAliveCoords(x, y, this.board.aliveCoords)
        } else {
          this.alive++
        }
        for (let n = 0; n < neighbourCoords.length; n++) {
          let [x, y] = neighbourCoords[n]
          if (x >= this.board.numcols || x < 0) continue
          if (y >= this.board.numrows || y < 0) continue
          if (!this.isCellAlive(x, y, this.originalAliveCoords)) {
            let key = x + ',' + y
            if (allDeadNeighbours[key] === undefined) {
              allDeadNeighbours[key] = 0
            }
            allDeadNeighbours[key]++
          }
        }
      }
    }
    for (let key in allDeadNeighbours) {
      if (allDeadNeighbours[key] === 3) {
        let coords = key.split(',')
        let [x, y] = [parseInt(coords[0], 10), parseInt(coords[1], 10)]
        this.addToAliveCoords(x, y, this.board.aliveCoords)
        this.alive++
      }
    }
  }
nextGeneration ( ) { this . originalAliveCoords = this . clone ( this . board . aliveCoords ) this . alive = 0 let allDeadNeighbours = { } for ( let y in this . board . aliveCoords ) { y = parseInt ( y , 10 ) let xHash = this . board . aliveCoords [ y ] for ( let x in xHash ) { x = parseInt ( x , 10 ) let neighbourCoords = this . getNeighbourCoords ( x , y ) let aliveNeighbourCount = this . getAliveNeighbourCount ( x , y , neighbourCoords ) if ( aliveNeighbourCount < 2 || aliveNeighbourCount > 3 ) { this . removeFromAliveCoords ( x , y , this . board . aliveCoords ) } else { this . alive ++ } for ( let n = 0 ; n < neighbourCoords . length ; n ++ ) { let [ x , y ] = neighbourCoords [ n ] if ( x >= this . board . numcols || x < 0 ) continue if ( y >= this . board . numrows || y < 0 ) continue if ( ! this . isCellAlive ( x , y , this . originalAliveCoords ) ) { let key = x + ',' + y if ( allDeadNeighbours [ key ] === undefined ) { allDeadNeighbours [ key ] = 0 } allDeadNeighbours [ key ] ++ } } } } for ( let key in allDeadNeighbours ) { if ( allDeadNeighbours [ key ] === 3 ) { let coords = key . split ( ',' ) let [ x , y ] = [ parseInt ( coords [ 0 ] , 10 ) , parseInt ( coords [ 1 ] , 10 ) ] this . addToAliveCoords ( x , y , this . board . aliveCoords ) this . alive ++ } } }
Rules:
 1) Any live cell with fewer than two live neighbours dies, as if caused by under-population.
Rules : 1 ) Any live cell with fewer than two live neighbours dies as if caused by under - population .
// Loop through alive coords. // Get hash of all x coords with the same y coord. // Under-population or overcrowding... // Keep count of dead neighbours. // Check for reproduction case.