Implement a function that simulates a simple finite state machine.
HardProblem Statement
Implement a function that simulates a simple finite state machine.
Sample Input
Define states and transitions for a light switch (on/off).
Sample Output
off on
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
// Simulate a finite state machine
function createStateMachine(initialState, transitions) {
// Initialize state and define methods to transition states
}
const lightSwitch = createStateMachine("off", {
off: { toggle: "on" },
on: { toggle: "off" }
});
console.log(lightSwitch.currentState); // "off"
lightSwitch.send("toggle");
console.log(lightSwitch.currentState); // "on"
Input
Define states and transitions for a light switch (on/off).
Expected Output
off on