Created
February 7, 2017 06:59
-
-
Save lykkin/99e55500ea870e581388107efcde6ba1 to your computer and use it in GitHub Desktop.
trie me
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
var hash = { | |
trie: {}, | |
store(k, v) { | |
let current = this.trie | |
k.split('').forEach((letter) => { | |
if (!this.trie[letter]) { | |
this.trie[letter] = {} | |
} | |
current = this.trie[letter] | |
}) | |
current.val = v | |
}, | |
get(k) { | |
var current = this.trie | |
k.split('').forEach((letter) => { | |
if (!this.trie[letter]) { | |
return | |
} | |
current = this.trie[letter] | |
}) | |
return current.val | |
} | |
} | |
hash.store('asdf', 1234) | |
console.log(hash.get('asdf')) | |
console.log(hash.get('as')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment