1.0.3 • Published 6 years ago

u-trie-js v1.0.3

Weekly downloads
58
License
DO_WHATEVER_YOU_W...
Repository
github
Last release
6 years ago

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.

Version License Build Status

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

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago