Given a two-dimensional array of maze and an array of directions. Your task is to follow the given directions.
"Finish"."Dead"."Lost".The maze array will look like this:
maze = [
[1, 1, 1, 1, 1, 1, 1, 1, 0, 1],
[1, 3, 1, 0, 1, 0, 0, 0, 0, 1],
[1, 0, 1, 0, 0, 0, 1, 1, 0, 1],
[1, 0, 1, 1, 1, 1, 1, 0, 0, 1],
[1, 0, 1, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 1, 0, 1, 0, 1, 0, 0, 1],
[1, 0, 1, 0, 1, 0, 0, 0, 0, 0],
[1, 0, 1, 0, 1, 0, 1, 1, 0, 1],
[1, 0, 0, 0, 1, 0, 0, 0, 0, 1],
[1, 1, 1, 0, 1, 1, 1, 1, 2, 1]
]
// 0 = Safe place to walk
// 1 = Wall
// 2 = Start Point
// 3 = Finish Point
// N = North, E = East, W = West and S = South
See the below examples for a better understanding:
exitMaze(maze, ["N", "E", "E"]) ➞ "Dead"
// Hitting the wall should return "Dead".
exitMaze(maze, ["N", "N", "N", "E"]) ➞ "Lost"
// Couldn't reach the finish point.
exitMaze(maze, ["N", "W", "W", "W", "N", "N", "N", "N", "W", "W", "S", "S", "S", "S", "W", "W", "N", "N", "N", "N", "N", "N", "N"]) ➞ "Finish"
N/A