Published
Edited
Nov 4, 2021
3 forks
2 stars
Insert cell
Insert cell
Insert cell
function inDictionary(word) {
word = word.toLowerCase();
let node = words_trie;
for (const char of word) {
let nextNode = node[char];
if (!nextNode) return false;
node = nextNode;
}
return node.__ === 1;
}
Insert cell
words_trie = {
const root = {};
// generate trie from each word
for (const word of words_list) {
let node = root;
// for each character in the word, either advance
// into the existing matching node, or if no
// matching character node is in the trie yet,
// create the node and avance into that
for (const char of word) {
let nextNode = node[char];
if (!nextNode) {
node[char] = nextNode = {};
}
node = nextNode;
}
node.__ = 1; // mark the nodes that are endings of real words
}
return root;
}
Insert cell
words_list = {
const words_string = await words.text();
return words_string.split("\r\n");
}
Insert cell
words = FileAttachment("words_alpha.txt")
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more