Paper theatre backdrop playback repeats both turning frames
Level 1 · node · Correctness · Duplicated turning points in a ping-pong playback cycle
Scenario
A fictional paper theatre studio builds one repeating playback cycle from a list of moving backdrop frames. The frames advance from first to last and then travel in reverse. In the preview, movement appears to pause briefly at both ends when direction changes. Review the cycle builder and preview entry point.
Requirements
preview(frames) accepts an array of frame names and returns one repeatable ping-pong cycle. Visit the frames from first to last in input order, then append only the interior frames in reverse order. The next cycle starts at the first frame again. Equal frame names at different array positions represent separate frames. Empty and single-frame inputs return a new array with the same contents. Do not mutate the input.
Acceptance criteria
- Handle empty and single-frame arrays correctly.
- For two frames, include each position once per cycle.
- For three or more frames, include the reverse interior frames without unnecessary pauses at either end.
- Preserve interior frames with equal names by position and do not mutate the input.