JS implementation of trie