function minesweeper(matrix) {
  let outMatrix = matrix.map((e) => {
    return Array.isArray(e) ? e.map((e) => 0) : 0;
  });

  for (let index = 0; index < matrix.length; index++) {
    let row = matrix[index];
    for (let j = 0; j < row.length; j++) {
      const element = row[j];
      if (element == true) {
        if(outMatrix[index][j + 1] != undefined) outMatrix[index][j + 1]++;
        if(outMatrix[index][j - 1] != undefined) outMatrix[index][j - 1]++;
        if(outMatrix[index + 1] != undefined) {
          if(outMatrix[index + 1][j + 1] != undefined) outMatrix[index + 1][j + 1]++;
          if(outMatrix[index + 1][j] != undefined) outMatrix[index + 1][j]++;
          if(outMatrix[index + 1][j - 1] != undefined) outMatrix[index + 1][j - 1]++;
        }
        if (outMatrix[index - 1] != undefined) {
          if(outMatrix[index - 1][j + 1] != undefined) outMatrix[index - 1][j + 1]++;
        if(outMatrix[index - 1][j] != undefined) outMatrix[index - 1][j]++;
        if(outMatrix[index - 1][j - 1] != undefined) outMatrix[index - 1][j - 1]++;
        }
        
        
      }
    }
    
  }
return outMatrix


  
}
/**
 * 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 outMatrix = matrix.map((e) => {
    return Array.isArray(e) ? e.map((e) => 0) : 0;
  });
  for (let index = 0; index < matrix.length; index++) {
    let row = matrix[index];
    for (let j = 0; j < row.length; j++) {
      const element = row[j];
      if (element == true) {
        if(outMatrix[index][j + 1] != undefined) outMatrix[index][j + 1]++;
        if(outMatrix[index][j - 1] != undefined) outMatrix[index][j - 1]++;
        if(outMatrix[index + 1] != undefined) {
          if(outMatrix[index + 1][j + 1] != undefined) outMatrix[index + 1][j + 1]++;
          if(outMatrix[index + 1][j] != undefined) outMatrix[index + 1][j]++;
          if(outMatrix[index + 1][j - 1] != undefined) outMatrix[index + 1][j - 1]++;
        }
        if (outMatrix[index - 1] != undefined) {
          if(outMatrix[index - 1][j + 1] != undefined) outMatrix[index - 1][j + 1]++;
        if(outMatrix[index - 1][j] != undefined) outMatrix[index - 1][j]++;
        if(outMatrix[index - 1][j - 1] != undefined) outMatrix[index - 1][j - 1]++;
        }
      }
    }
  }
return outMatrix
}
function minesweeper ( matrix ) { let outMatrix = matrix . map ( ( e ) => { return Array . isArray ( e ) ? e . map ( ( e ) => 0 ) : 0 ; } ) ; for ( let index = 0 ; index < matrix . length ; index ++ ) { let row = matrix [ index ] ; for ( let j = 0 ; j < row . length ; j ++ ) { const element = row [ j ] ; if ( element == true ) { if ( outMatrix [ index ] [ j + 1 ] != undefined ) outMatrix [ index ] [ j + 1 ] ++ ; if ( outMatrix [ index ] [ j - 1 ] != undefined ) outMatrix [ index ] [ j - 1 ] ++ ; if ( outMatrix [ index + 1 ] != undefined ) { if ( outMatrix [ index + 1 ] [ j + 1 ] != undefined ) outMatrix [ index + 1 ] [ j + 1 ] ++ ; if ( outMatrix [ index + 1 ] [ j ] != undefined ) outMatrix [ index + 1 ] [ j ] ++ ; if ( outMatrix [ index + 1 ] [ j - 1 ] != undefined ) outMatrix [ index + 1 ] [ j - 1 ] ++ ; } if ( outMatrix [ index - 1 ] != undefined ) { if ( outMatrix [ index - 1 ] [ j + 1 ] != undefined ) outMatrix [ index - 1 ] [ j + 1 ] ++ ; if ( outMatrix [ index - 1 ] [ j ] != undefined ) outMatrix [ index - 1 ] [ j ] ++ ; if ( outMatrix [ index - 1 ] [ j - 1 ] != undefined ) outMatrix [ index - 1 ] [ j - 1 ] ++ ; } } } } return outMatrix }
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 .