MediumPro challengeTypeScript

Command

TypeScriptDesign PatternsBehavioralCommand

Encapsulate a request as an object so it can be queued, logged, or undone — instead of calling light.turnOn() directly, you execute a LightOnCommand.

Implement `LightOnCommand`/`LightOffCommand` (execute()/undo()) and the solve history stack that supports 'undo'.

solve(ops) runs a sequence of 'on' | 'off' | 'undo' against a Light, pushing every executed command onto a history stack that 'undo' pops and reverses, and returns { isOn, historyLength }.

Sample tests

Test #1Single on command
Input: [["on"]]
Output: {"isOn":true,"historyLength":1}
Test #2Undo reverses the last command (off → back on)
Input: [["on","off","undo"]]
Output: {"isOn":true,"historyLength":1}
Test #3Undo the only command empties history
Input: [["on","undo"]]
Output: {"isOn":false,"historyLength":0}