Skip to content

Instantly share code, notes, and snippets.

@olslash
Last active August 29, 2015 14:05
Show Gist options
  • Save olslash/6cc6859e53d19a45e174 to your computer and use it in GitHub Desktop.
Save olslash/6cc6859e53d19a45e174 to your computer and use it in GitHub Desktop.
T9 blogpost - 3
Trie.prototype.insert = function(word, useFrequency) {
// Traverse the tree to the node where the word should be inserted. If any
// needed nodes do not exist along the way, they are created.
var nodeToAddWord = traverseAddingNodes(this);
// Insert the word into the wordlist of the node returned above. Use the
// data provided (frequency of use in English text) to place the word in
// the correct position, so that we can recommend more common words first.
insertWordIntoListByFrequency(nodeToAddWord.words, word, useFrequency);
function traverseAddingNodes(node) {
// ...
}
function insertWordIntoListByFrequency(list, word, useFrequency) {
// ...
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment