Skip to content

Instantly share code, notes, and snippets.

@greyscaled
Last active August 20, 2018 03:56
Show Gist options
  • Save greyscaled/eabf9cf6e00b09f77c5a22ba2b88a77c to your computer and use it in GitHub Desktop.
Save greyscaled/eabf9cf6e00b09f77c5a22ba2b88a77c to your computer and use it in GitHub Desktop.
class Trie {
constructor () {
this.root = new Node()
}
put (key = '', val = null) {
this.root = recursiveInsert(this.root, key, val, 0)
}
// ...
}
const recursiveInsert = (node, key, val, d) => {
// private helper method to insert a key/val through
// a recursive walk
}
if (process.env.NODE_ENV === 'test') {
// only expose private methods for testing
module.exports = {
Trie,
recursiveInsert
}
else {
// in production, development - only Trie is exposed
module.exports = Trie
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment