β¨ 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;
}