Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@jasonheecs/js-data-structures

jasonheecs18MIT1.2.0

A list of common data structures implemented in Javascript

data structures, linked list, binary search tree, queue, stack, trie, min heap, doubly linked list, circular linked list

readme

Data Structures in Javascript

Build Status Coverage Status

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

Installation

npm install @jasonheecs/js-data-structures --save

Data Structures

Usage

    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 } **/

Running unit tests

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

License

MIT