constfind=(maze,N,num)=>{for(leti=0;i<N;i++){letindex=maze[i].indexOf(num)if(index>-1)return[i,index]}return-1}constreach=(maze,direction)=>{if(!maze||!Array.isArray(maze)||maze[0].length!==maze.length)thrownewError("invalid argument")constN=maze[0].lengthletstart=find(maze,N,2)if(start<0)thrownewError("start point not found")letfinish=find(maze,N,3)if(finish<0)thrownewError("finish point not found")for(leti=0;i<direction.length;i++){switch(direction[i]){case"E":start=[start[0],start[1]+1];break;case"W":start=[start[0],start[1]-1]break;case"N":start=[start[0]-1,start[1]]break;case"S":start=[start[0]+1,start[1]]break;default:thrownewError("unidentified direction")}if(start[0]<0||start[0]>=N||start[1]<0||start[1]>=N||maze[start[0]][start[1]]===1){return"Dead"}}if(start[0]===finish[0]&&start[1]===finish[1])return"Finish"return"Lost"}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
ES6