Alert at Santa's toy factory! The Grinch π has infiltrated the warehouse and sabotaged some of the toys π£.
The elves need help to find the sabotaged toys and remove them before Christmas comes. For this, we have the warehouse map πΊοΈ, which is a matrix.
The *
represent the sabotaged toys, and empty cells with a blank space are safe places.
Your task is to write a function that returns the same matrix but, at each position, shows us the number of sabotaged toys in the adjacent cells.
If a cell contains a sabotaged toy, it should remain the same. If a cell does not touch any sabotaged toy, it should contain a blank space .
const store = [
['*', ' ', ' ', ' '],
[' ', ' ', '*', ' '],
[' ', ' ', ' ', ' '],
['*', ' ', ' ', ' ']
]
console.log(revealSabotage(board))
/* Should display:
[
['*', '2', '1', '1'],
['1', '2', '*', '1'],
['1', '2', '1', '1'],
['*', '1', ' ', ' ']
]
*/
Keep in mind thatβ¦
and a sabotaged toy *
.