function solution(board) {
let answer = 0;
// 지뢰인접지역(=위험지역)의 좌표
let dangerArea = [
[-1, -1], [-1, 0], [-1, 1],
[0, -1], [0, 1],
[1, -1], [1, 0], [1, 1]
];
for (let x=0; x<board.length; x++) {
for (let y=0; y<board[x].length; y++) {
if (board[x][y] == 1) {
dangerArea.map(area => {
let [tempX, tempY] = area;
[tempX, tempY] = [tempX + x, tempY + y];
if (tempX >= 0 && tempX <= board.length-1 &&
tempY >=0 && tempY <= board[x].length-1 &&
board[tempX][tempY] == 0
) {
board[tempX][tempY] = 2;
}
});
}
}
}
board.map(row => row.map(spot => spot == 0 ? answer++ : 0));
return answer;
}