src/04-mine-sweeper.js
/**
 * In the popular Minesweeper game you have a board with some mines and those cells
 * that don't contain a mine have a number in it that indicates the total number of mines
 * in the neighboring cells. Starting off with some arrangement of mines
 * we want to create a Minesweeper game setup.
 *
 * @param {Array<Array>} matrix
 * @return {Array<Array>}
 *
 * @example
 * matrix = [
 *  [true, false, false],
 *  [false, true, false],
 *  [false, false, false]
 * ]
 *
 * The result should be following:
 * [
 *  [1, 2, 1],
 *  [2, 1, 1],
 *  [1, 1, 1]
 * ]
 */
In the popular Minesweeper game you have a board with some mines and those cells
that don't contain a mine have a number in it that indicates the total number of mines
in the neighboring cells. Starting off with some arrangement of mines
we want to create a Minesweeper game setup.

@param {Array} matrix
@return {Array}




In the popular Minesweeper game you have a board with some mines and those cells that don ' t contain a mine have a number in it that indicates the total number of mines in the neighboring cells . Starting off with some arrangement of mines we want to create a Minesweeper game setup . @param { Array } matrix @return { Array }
function minesweeper(matrix) {
  const minMap = matrix.map((row) => row.map(() => 0));
  matrix.forEach((row, rindex) => {
    row.forEach((item, cindex) => {
      if (item) {
        if (cindex > 0) minMap[rindex][cindex - 1] += 1;
        if (cindex < row.length - 1) minMap[rindex][cindex + 1] += 1;
        if (rindex > 0) {
          if (cindex > 0) minMap[rindex - 1][cindex - 1] += 1;
          minMap[rindex - 1][cindex] += 1;
          if (cindex < row.length - 1) minMap[rindex - 1][cindex + 1] += 1;
        }
        if (rindex < matrix.length - 1) {
          if (cindex > 0) minMap[rindex + 1][cindex - 1] += 1;
          minMap[rindex + 1][cindex] += 1;
          if (cindex < row.length - 1) minMap[rindex + 1][cindex + 1] += 1;
        }
      }
    });
  });
  return minMap;
}
function minesweeper ( matrix ) { const minMap = matrix . map ( ( row ) => row . map ( ( ) => 0 ) ) ; matrix . forEach ( ( row , rindex ) => { row . forEach ( ( item , cindex ) => { if ( item ) { if ( cindex > 0 ) minMap [ rindex ] [ cindex - 1 ] += 1 ; if ( cindex < row . length - 1 ) minMap [ rindex ] [ cindex + 1 ] += 1 ; if ( rindex > 0 ) { if ( cindex > 0 ) minMap [ rindex - 1 ] [ cindex - 1 ] += 1 ; minMap [ rindex - 1 ] [ cindex ] += 1 ; if ( cindex < row . length - 1 ) minMap [ rindex - 1 ] [ cindex + 1 ] += 1 ; } if ( rindex < matrix . length - 1 ) { if ( cindex > 0 ) minMap [ rindex + 1 ] [ cindex - 1 ] += 1 ; minMap [ rindex + 1 ] [ cindex ] += 1 ; if ( cindex < row . length - 1 ) minMap [ rindex + 1 ] [ cindex + 1 ] += 1 ; } } } ) ; } ) ; return minMap ; }
In the popular Minesweeper game you have a board with some mines and those cells
 that don't contain a mine have a number in it that indicates the total number of mines
 in the neighboring cells.
In the popular Minesweeper game you have a board with some mines and those cells that don ' t contain a mine have a number in it that indicates the total number of mines in the neighboring cells .