function createGrid(oldGrid) {
  const grid = [];

  for (let i = 0; i < GRID_COLUMNS; i++) {
    const column = [];

    for (let j = 0; j < GRID_ROWS; j++) {
      const cell = {
        // when a disc is placed in this cell, it will be marked with the turn it was used
        // the player can be derived from the turn -- all even turns will be player 1, and odd for 2
        usedAtTurn: -1
      };

      if (oldGrid) {
        // assuming oldGrid is of same size
        cell.usedAtTurn = oldGrid[i][j].usedAtTurn;
      }

      column.push(cell);
    }
    grid.push(column);
  }

  return grid;
}
/**
 * Create a new blank grid, optionally copying over data from existing grid.
 *
 * @param oldGrid
 * @returns {Array}
 */
Create a new blank grid, optionally copying over data from existing grid.
@param oldGrid
@returns {Array}
Create a new blank grid optionally copying over data from existing grid . @param oldGrid @returns { Array }
function createGrid(oldGrid) {
  const grid = [];
  for (let i = 0; i < GRID_COLUMNS; i++) {
    const column = [];
    for (let j = 0; j < GRID_ROWS; j++) {
      const cell = {
        usedAtTurn: -1
      };
      if (oldGrid) {
        cell.usedAtTurn = oldGrid[i][j].usedAtTurn;
      }
      column.push(cell);
    }
    grid.push(column);
  }
  return grid;
}
function createGrid ( oldGrid ) { const grid = [ ] ; for ( let i = 0 ; i < GRID_COLUMNS ; i ++ ) { const column = [ ] ; for ( let j = 0 ; j < GRID_ROWS ; j ++ ) { const cell = { usedAtTurn : - 1 } ; if ( oldGrid ) { cell . usedAtTurn = oldGrid [ i ] [ j ] . usedAtTurn ; } column . push ( cell ) ; } grid . push ( column ) ; } return grid ; }
Create a new blank grid, optionally copying over data from existing grid.
Create a new blank grid optionally copying over data from existing grid .
// when a disc is placed in this cell, it will be marked with the turn it was used // the player can be derived from the turn -- all even turns will be player 1, and odd for 2 // assuming oldGrid is of same size