function minesweeper(matrix) {
  let xPosition;
  let yPosition;
  const result = [];
  const countMines = () => {
    let mineCounter = 0;
    if (xPosition > 0) {
      mineCounter = matrix[xPosition - 1][yPosition] ? mineCounter + 1 : mineCounter;
      if (yPosition > 0) {
        mineCounter = matrix[xPosition - 1][yPosition - 1] ? mineCounter + 1 : mineCounter;
      }
      if (yPosition < matrix[xPosition].length - 1) {
        mineCounter = matrix[xPosition - 1][yPosition + 1] ? mineCounter + 1 : mineCounter;
      }
    }
    if (xPosition < matrix.length - 1) {
      mineCounter = matrix[xPosition + 1][yPosition] ? mineCounter + 1 : mineCounter;
      if (yPosition > 0) {
        mineCounter = matrix[xPosition + 1][yPosition - 1] ? mineCounter + 1 : mineCounter;
      }
      if (yPosition < matrix[xPosition].length - 1) {
        mineCounter = matrix[xPosition + 1][yPosition + 1] ? mineCounter + 1 : mineCounter;
      }
    }
    if (yPosition > 0) {
      mineCounter = matrix[xPosition][yPosition - 1] ? mineCounter + 1 : mineCounter;
    }
    if (yPosition < matrix[xPosition].length - 1) {
      mineCounter = matrix[xPosition][yPosition + 1] ? mineCounter + 1 : mineCounter;
    }
    return mineCounter;
  };

  for (xPosition = 0; xPosition < matrix.length; xPosition++) {
    result[xPosition] = [];
    for (yPosition = 0; yPosition < matrix[xPosition].length; yPosition++) {
      result[xPosition][yPosition] = countMines() === 0
        ? 0 : countMines();
    }
  }
  return result;
}
/**
 * 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) {
  let xPosition;
  let yPosition;
  const result = [];
  const countMines = () => {
    let mineCounter = 0;
    if (xPosition > 0) {
      mineCounter = matrix[xPosition - 1][yPosition] ? mineCounter + 1 : mineCounter;
      if (yPosition > 0) {
        mineCounter = matrix[xPosition - 1][yPosition - 1] ? mineCounter + 1 : mineCounter;
      }
      if (yPosition < matrix[xPosition].length - 1) {
        mineCounter = matrix[xPosition - 1][yPosition + 1] ? mineCounter + 1 : mineCounter;
      }
    }
    if (xPosition < matrix.length - 1) {
      mineCounter = matrix[xPosition + 1][yPosition] ? mineCounter + 1 : mineCounter;
      if (yPosition > 0) {
        mineCounter = matrix[xPosition + 1][yPosition - 1] ? mineCounter + 1 : mineCounter;
      }
      if (yPosition < matrix[xPosition].length - 1) {
        mineCounter = matrix[xPosition + 1][yPosition + 1] ? mineCounter + 1 : mineCounter;
      }
    }
    if (yPosition > 0) {
      mineCounter = matrix[xPosition][yPosition - 1] ? mineCounter + 1 : mineCounter;
    }
    if (yPosition < matrix[xPosition].length - 1) {
      mineCounter = matrix[xPosition][yPosition + 1] ? mineCounter + 1 : mineCounter;
    }
    return mineCounter;
  };
  for (xPosition = 0; xPosition < matrix.length; xPosition++) {
    result[xPosition] = [];
    for (yPosition = 0; yPosition < matrix[xPosition].length; yPosition++) {
      result[xPosition][yPosition] = countMines() === 0
        ? 0 : countMines();
    }
  }
  return result;
}
function minesweeper ( matrix ) { let xPosition ; let yPosition ; const result = [ ] ; const countMines = ( ) => { let mineCounter = 0 ; if ( xPosition > 0 ) { mineCounter = matrix [ xPosition - 1 ] [ yPosition ] ? mineCounter + 1 : mineCounter ; if ( yPosition > 0 ) { mineCounter = matrix [ xPosition - 1 ] [ yPosition - 1 ] ? mineCounter + 1 : mineCounter ; } if ( yPosition < matrix [ xPosition ] . length - 1 ) { mineCounter = matrix [ xPosition - 1 ] [ yPosition + 1 ] ? mineCounter + 1 : mineCounter ; } } if ( xPosition < matrix . length - 1 ) { mineCounter = matrix [ xPosition + 1 ] [ yPosition ] ? mineCounter + 1 : mineCounter ; if ( yPosition > 0 ) { mineCounter = matrix [ xPosition + 1 ] [ yPosition - 1 ] ? mineCounter + 1 : mineCounter ; } if ( yPosition < matrix [ xPosition ] . length - 1 ) { mineCounter = matrix [ xPosition + 1 ] [ yPosition + 1 ] ? mineCounter + 1 : mineCounter ; } } if ( yPosition > 0 ) { mineCounter = matrix [ xPosition ] [ yPosition - 1 ] ? mineCounter + 1 : mineCounter ; } if ( yPosition < matrix [ xPosition ] . length - 1 ) { mineCounter = matrix [ xPosition ] [ yPosition + 1 ] ? mineCounter + 1 : mineCounter ; } return mineCounter ; } ; for ( xPosition = 0 ; xPosition < matrix . length ; xPosition ++ ) { result [ xPosition ] = [ ] ; for ( yPosition = 0 ; yPosition < matrix [ xPosition ] . length ; yPosition ++ ) { result [ xPosition ] [ yPosition ] = countMines ( ) === 0 ? 0 : countMines ( ) ; } } return result ; }
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 .