function Automaton() {
this.stateMap = {
'0': {
'0': '0',
'1': '1',
},
'1': {
'0': '2',
'1': '1',
},
'2': {
'1': '1',
'0': '1',
}
};
}
Automaton.prototype.readCommands = function (commands, state = '0', acceptState = '1') {
if (commands.length === 0) {
return acceptState === state;
}
return this.readCommands(commands.slice(1), this.stateMap[state][commands.shift()], acceptState);
};
var myAutomaton = new Automaton();