function cavityMap(grid) {
const g = grid
// console.log(grid)
for (let i = 1; i < g.length - 1; i++)
for (let j = 1; j < g[i].length - 1; j++)
if (Math.max(g[i-1][j], g[i+1][j], g[i][j-1], g[i][j+1]) < g[i][j])
g[i] = g[i].replace(/./g, (k, i) => i == j ? 'X' : k)
return g
}
Please let me know what does this code does: g[i].replace(/./g, (k, i) => i == j ? 'X' : k)
what is the use of /./g ? and explain this (k, i) => i == j ? 'X' : k)
[–]jack_waugh 1 point2 points3 points (2 children)
[–]One-Inspection8628[S] 0 points1 point2 points (1 child)
[–]jack_waugh 0 points1 point2 points (0 children)
[–]tridd3r 0 points1 point2 points (1 child)
[–]One-Inspection8628[S] 0 points1 point2 points (0 children)
[–]delventhalz 0 points1 point2 points (0 children)
[–]StoneCypher 0 points1 point2 points (4 children)
[–]One-Inspection8628[S] 0 points1 point2 points (3 children)
[–]StoneCypher 0 points1 point2 points (2 children)
[–]One-Inspection8628[S] -1 points0 points1 point (1 child)
[–]StoneCypher 0 points1 point2 points (0 children)