The Killer Garage Door exercise

January 19, 2021

I had the chance to do the Killer Garage Door exercise in an interview recently.

This seems like a classic state machine problem. You have a garage door that opens and closes in response to button presses and potential obstacles encountered during movement.

Example states the garage door can be in: opening, closing, fully opened, fully closed, etc.

The exercise is pretty fun and educational, so I definitely recommend you attempt it in your own free time. Submitting the exercise shows you some pretty cool answers too (my submission is here - definitely not as clever as some others - also ignore the no-op parseEvent function at the top, I forgot to remove it!).

After reviewing others' answers, I went and create a React app for the exercise. You can view the Codesandbox here. I'll update this sandbox to an actual web app and write up more details in due course.

In the meantime, enjoy this GIF of the web app in action:

killer garage door React app gif