Skip to content
RSS feed tkhwang on GitHub tkhwang on Twitter

πŸ”₯ Trie in javascript

✨ Algorithm

  • Very simple implementation.
  • Check word ending using "word" field.
const trie = {};

for (const word of words) {
  let node = trie;
  for (const ch of word) {
    if (node[ch] === undefined) node[ch] = {};
    node = node[ch];
  }
  node["word"] = word;
}

πŸ—’οΈ Typical problems