npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

js-linkedlist

v1.0.2

Published

Simple implementation of linked list data structure

Downloads

1

Readme

Usage

        const List = require('js-linkedlist').LinkedList;
        const Node = require('js-linkedlist').Node;

        let myNode = new Node('33');
        let mylist = new List();

Node Class API Function Arguments Returns Directions Example Node.constructor (Data, Node) Node Creates a class instance to represent a node. The node should have two properties, 'data' and 'next'. Accept both of these as arguments to the 'Node' constructor, then assign them to the instance as properties 'data' and 'next'. If 'next' is not provided to the constructor, then default its value to be 'null'.

        const n = new Node('There');
        n.data // 'Hi'
        n.next // null
        const n2 = new Node('Hi', n);
        n.next // returns n
      

LinkedList Class API Function Arguments Returns Directions Example constructor - (LinkedList) Create a class to represent a linked list. When created, a linked list should have no head node associated with it. The LinkedList instance will have one property, 'head', which is a reference to the first node of the linked list. By default 'head' should be 'null'.

        const list = new LinkedList();
        list.head // null
      

insertFirst (data) - Creates a new Node from argument 'data' and assigns the resulting node to the 'head' property. Make sure to handle the case in which the linked list already has a node assigned to the 'head' property.

        const list = new LinkedList();
        list.insertFirst('Hi There'); // List has one node
      

size - (integer) Returns the number of nodes in the linked list.

        const list = new LinkedList();
        list.insertFirst('a');
        list.insertFirst('b');
        list.insertFirst('c');
        list.size(); // returns 3
      

getFirst - (Node) Returns the first node of the linked list.

        const list = new LinkedList();
        list.insertFirst('a');
        list.insertFirst('b');
        list.getFirst(); // returns Node instance with data 'a'
      

getLast - (Node) Returns the last node of the linked list

        const list = new LinkedList();
        list.insertFirst('a');
        list.insertFirst('b');
        list.getLast(); // returns node with data 'a'
      

clear - - Empties the linked list of any nodes.

        const list = new LinkedList();
        list.insertFirst('a');
        list.insertFirst('b');
        list.clear();
        list.size(); // returns 0
      

removeFirst - - Removes only the first node of the linked list. The list's head should now be the second element.

        const list = new LinkedList();
        list.insertFirst('a');
        list.insertFirst('b');
        list.removeFirst();
        list.getFirst(); // returns node with data 'a'
      

removeLast - - Removes the last node of the chain

        const list = new LinkedList();
        list.insertFirst('a');
        list.insertFirst('b');
        list.removeLast();
        list.size(); // returns 1
        list.getLast(); // returns node with data of 'b'
      

insertLast (Data) - Inserts a new node with provided data at the end of the chain

        const list = new LinkedList();
        list.insertFirst('a');
        list.insertFirst('b');
        list.insertLast('c');
        list.getLast(); // returns node with data 'C'
      

getAt (integer) (Node) Returns the node at the provided index

        const list = new List();
        list.insertFirst('a');
        list.insertFirst('b');
        list.insertFirst('c');
        list.getAt(1); // returns node with data 'b'
      

removeAt (integer) - Removes node at the provided index

        const list = new List();
        list.insertFirst('a');
        list.insertFirst('b');
        list.insertFirst('c');
        list.removeAt(1);
        list.getAt(1); // returns node with data 'a'
      

insertAt (Data, integer) - Create an insert a new node at provided index. If index is out of bounds, add the node to the end of the list.

        const list = new List();
        list.insertFirst('a');
        list.insertFirst('b');
        list.insertFirst('c');
        list.insertAt('Hi', 1)
        list.getAt(1); // returns node with data 'Hi'
      

forEach (function) - Calls the provided function with every node of the chain

        const list = new List();

        list.insertLast(1);
        list.insertLast(2);
        list.insertLast(3);
        list.insertLast(4);

        list.forEach(node => {
          node.data += 10;
        });
        list.getAt(0); // Returns node with data '11'
      

for...of Loop - - Linked list should be compatible as the subject of a 'for...of' loop

        const list = new List();

        list.insertLast(1);
        list.insertLast(2);
        list.insertLast(3);
        list.insertLast(4);

        for (let node of list) {
          node.data += 10;
        }

        node.getAt(1); // returns node with data 11