Implementation of DFA in JavaScript