Ctrl K
Frontend · Mid-level · Coding

Write an EventEmitter class with the methods on, off, emit, and once. The on method subscribes a handler to an event by name, off unsubscribes it, emit calls all of the event's handlers with the given arguments, and once subscribes a handler that fires only once.

~15 min by voice

How to approach it

They're checking whether you can design a small API with mutable state: choose a storage structure, remove handlers correctly, and handle the subtle cases. The main ones are once as a wrapper, off by the original reference, and the list changing during emit.

Have you seen this question in a real interview?
Answers0
Avg. score—
Strong—
Practiced0
Topics

Answer by voice

The interviewer will ask this question and listen. Think out loud and ask for a hint if you need one. When you're done, pause or tap “That's my answer”. In about a minute, your score and the points you covered show up here.

Sign in to answer

Best with headphones · ~15 min