Created
April 1, 2016 09:59
-
-
Save kwijibo/2069e0ec6f3e4b320c0124dc0b25c991 to your computer and use it in GitHub Desktop.
Search Trie
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const branchLetter = ({full, sub},letter) => { | |
sub[letter] = sub[letter] || {} | |
return {full, sub: sub[letter] } | |
} | |
const indexWord = (trie, word) => { | |
const {full, sub} = word.split('').reduce(branchLetter, {full:trie, sub: trie}) | |
return full | |
} | |
const indexText = text => text.split(' ').reduce(indexWord, {}) | |
const index = indexText('It would be easy to say that error handling is a black art in software development but that implies that there is some secret stash of knowledge out there. The truth is that we tend to think of error handling as a lesser concern.') | |
console.log(index) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment