A package containing implementations of various data structures in Javascript. This project is mainly a learning exercise and personal refresher on the common CS data structures, in addition to playing around with test coverage reports with coveralls
npm install @jasonheecs/js-data-structures --save
- Binary Search Tree
- Singly Linked List
- Doubly Linked List
- Circular Linked List
- Queue
- Stack
- Trie
- Min Heap
- Graph
var {BST} = require('@jasonheecs/js-data-structures');
var {List} = require('@jasonheecs/js-data-structures');
var {Trie} = require('@jasonheecs/js-data-structures');
var bst = new BST();
bst.add(10);
bst.add(5);
bst.add(15);
console.log(bst.inOrder()); // [5, 10, 15]
var linkedList = new List();
linkedList.add(1);
linkedList.add(2);
linkedList.add(3);
console.log(linkedList.search(2)); // Node { value: 2, next: Node { value: 3, next: null } }
var trie = new Trie();
trie.addWord('cat');
trie.addWord('car');
trie.addWord('dog');
console.log(trie.find('ca'));
/** Node { value: 'a', children: Map {
't' => Node { value: 't', children: Map {}, isCompleteWord: true },
'r' => Node { value: 'r', children: Map {}, isCompleteWord: true } },
isCompleteWord: false } **/
npm test
To run a specific test file, you can use an extra --
to pass the filename through:
npm test -- test/binary-search-tree-test.js
MIT