Implement a JavaScript frame player controller
VerkadaSoftware Engineer · Technical ScreenLast updated
Implement a JavaScript frame player controller evaluates requirements, assumptions, structured reasoning, trade-offs, and verification in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.
You are given a skeleton for a frame-by-frame browser media player. Implement a JavaScript controller that:
- Jumps to any frame by index.
- Starts and pauses autoplay at a configurable frames-per-second (FPS).
- Exposes methods: play(), pause(), seek(frameIndex), setFPS(fps), currentFrame(), isPlaying().
- Uses setTimeout or setInterval correctly to schedule frames, handles timer drift, and prevents overlapping timers.
- Encapsulates internal state via closures and cleans up timers/listeners to avoid memory leaks. Explain your design and time-scheduling strategy, compare setTimeout vs setInterval (and optionally requestAnimationFrame) for this use case, and describe how you would handle edge cases (seeking while playing, invalid indices, reaching the last frame, resuming after pause). Provide pseudocode or tests showing expected behavior.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.