Translated trie code into Javascript.