Simple DFA implementation in Javascript.