-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcavityMap.js
More file actions
25 lines (24 loc) · 780 Bytes
/
cavityMap.js
File metadata and controls
25 lines (24 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function cavityMap(grid) {
let newMap = [];
let xValue = 0;
newMap[0] = grid[0];
for(let line = 1; line < grid.length -1; line++){
newMap[line] = grid[line][0];
for(let column = 1; column < grid[line].length-1; column++ ){
xValue = grid[line][column];
if(grid[line][column-1] < xValue
&& grid[line][column+1] < xValue
&& grid[line-1][column] < xValue
&& grid[line+1][column] < xValue){
newMap[line] += "X";
} else {
newMap[line] += xValue;
}
}
newMap[line] += grid[line][grid.length-1];
}
newMap[grid.length-1] = grid[grid.length-1];
return newMap;
}
let map = ["1112","1912","1892","1234"];
console.log(cavityMap(map));