MediumPro challengeTypeScript

State

TypeScriptDesign PatternsBehavioralState

Let an object change its behavior when its internal state changes, by delegating to a state object rather than a pile of if/switch statements — a traffic light that cycles Red → Green → Yellow → Red.

Implement `RedState`/`GreenState`/`YellowState`, each returning the NEXT state object from next().

solve(transitions) starts at Red and calls next() that many times, returning the full sequence of state names visited (including the starting state).

solve(1)['Red', 'Green']

Sample tests

Test #1No transitions — just the start state
Input: [0]
Output: ["Red"]
Test #2Full cycle back to Red
Input: [3]
Output: ["Red","Green","Yellow","Red"]
Test #3One transition
Input: [1]
Output: ["Red","Green"]