Generation

generate functionTue, 20 Jun 2023

Detective, we have a situation on our hands! The madman we've been hunting down got painted into a corner so he's holed up in the abandoned building that was scheduled to be torn down, with 4 innocent people as hostages. We still don't know who he is but we know he isMad. For each room, we want you to go through, see if anyone is there, and rescue them. But, we think the madman is hiding as one of the hostages. If you find him, don't bring him with you or he'll escape! You're the only one who can tell which one is the madman so we need you to find him. Return an array of the 4 hostages so we can have them accounted for, and then we'll sweep the building with the rest of the police so he can't possibly escape! You have a lot of rooms within rooms to search, so get cracking! const evilMaze = (maze) => {

const evilMaze = (maze) => { let results = [] let madman = false for(let i = 0; i < maze.length; i++) { if(typeof maze[i] === 'string') { if(maze[i] !== "madman") { results.push(maze[i]) } else { madman = true } } else { let r = evilMaze(maze[i]) if(madman === false) { results = results.concat(r) } else { results = results.concat(r.slice(0, r.indexOf("madman"))) } } } return results }

Javascript
Generate More

Questions about programming?Chat with your personal AI assistant