1.0.3 • Published 6 years ago
u-trie-js v1.0.3
u-trie-js
A 'micro' Trie implementation in Js for learning data structure design.
See HackerRank's excellent Tries video for a similar implementation in Java && a walkthrough of how Tries work.
Prerequisites
- NodeJs / NPM
Installation
npm i 'u-trie-js'
Testing
From your application code.
const uTrieJs = require('u-trie-js')
const myTrie = uTrieJs('dev')
console.log('myTrie --> ', myTrie)
API
Class: uTrieJs
const uTrieJs = require('u-trie-js')
const myTrie = uTrieJs('dev')
console.log(`\n\n Initial myTrie ---> %o\n\n`, myTrie)
myTrie.insert('Tesla', 'Is an awesome vehicle manufacturer!')
myTrie.insert('approxModel3price', 30000)
myTrie.insert('model3features', ['autopilot', 'regenerative braking'])
myTrie.insert('model3options', {leatherSeats: 500, extendedWarranty: 4000})
console.log(`\n\n Checking myTrie ---> %o\n\n`, myTrie)
myTrie.find('Tesla')
myTrie.find('approxModel3price')
myTrie.remove('approxModel3price')
myTrie.remove('model3features')
console.log(`\n\n Checking myTrie ---> %o\n\n`, myTrie)
Use insert()
to add keys with any type of value, nested values, etc., find()
to retrieve values by key && remove()
to delete keys and their stored values.
Methods
uTrieJs.find(word
)
word
- (string) - 'Any A-Z string value; case insensitive.'
Returns the word's Last Letter Node, if found; 0 if not found.
uTrieJs.insert(word
)
word
- (string) - 'Any A-Z string value; case insensitive.'
Returns the word's Last Letter Node to verify insertion.
uTrieJs.remove(word
)
word
- (string) - 'Any A-Z string value; case insensitive.'
Returns the Trie's Root Node to verify removal.
Contributing
Not currently accepting outside contributors, but feel free to clone, modify and use as you wish.
Authors
License
This project is licensed under the DO_WHATEVER_YOU_WANT License - see the LICENSE file for details
Acknowledgments
- Gayle Laakmann McDowell --- HackerRank YouTube