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

double-linked-list

v2.1.0

Published

A doubly-linked list implementation.

Downloads

7

Readme

Double Linked List

A JavaScript implementation of a doubly-linked list. Much faster than the native JS array if your focus is adding and removing from large data sets.

Slow if you need to randomly access elements from within the data set.

Installation

$ npm install double-linked-list

Use

var LinkedList = require('double-linked-list');

var list = new LinkedList();

Documentation

Method reference

#unShift

list.unShift(item);

Add an item to the start of the list.

list.unShift('one');
list.unShift('two');
list.unShift('three');
console.log(list.first()); // 'three'
console.log(list.last()); // 'one'

#push

list.push(item);

Add an item to the end of the list.

list.push('one');
list.push('two');
list.push('three');
console.log(list.last()); // 'three'
console.log(list.first()); // 'one'

#add

list.add(i, item);

Adds the item to the list at the given index. If the index is less than 0 it is appended to the front. If the index is greater than the length of the list it is appended to the end.

list.push('one');
list.push('two');
list.push('three');

list.add(1, 'hello');
list.add(2, 'you');
list.add(list.length, 'something'); // adds to the end of the list

console.log(list.get(1)); // 'hello'
console.log(list.get(2)); // 'you'
console.log(list.get(5)); // 'something'

#shift

list.shift();

Removes the item at the start of the list, returning the removed item. Returns undefined if the list is empty.

list.push('one');
list.push('two');
list.push('three');
console.log(list.shift()); // 'one'

#pop

list.pop();

Removes the item at the end of the list, returning the removed item. Returns undefined if the list is empty.

list.push('one');
list.push('two');
list.push('three');
console.log(list.pop()); // 'three'

#remove

list.remove(i);

Removes the item at the given index from the list, returning the removed item. Returns undefined if an invalid value is given.

list.push('one');
list.push('two');
list.push('three');

console.log(list.remove(1)); // 'two'

#first

list.first();

Returns the item at the start of the list. Returns undefined if the list is empty.

list.push('one');
list.push('two');
list.push('three');
console.log(list.first()); // 'one'

#last

list.last();

Returns the item at the end of the list. Returns undefined if the list is empty.

list.push('one');
list.push('two');
list.push('three');
console.log(list.last()); // 'three'

#get

list.get(i);

Returns the item at the given index. Returns undefined if an invalid value is given.

list.push('one');
list.push('two');
list.push('three');
console.log(list.get(0)); // 'one'
console.log(list.get(1)); // 'two'
console.log(list.get(2)); // 'three'
   

#toString

var listString = list.toString();

Returns the contents of the list as a readable string.

list.push('one');
list.push('two');
list.push('three');

console.log(list.toString()); // 'one, two, three'

list.push({hello: "this"});
list.push({goodbye: "that"});
console.log(list.toString()); // '{"hello":"this"}, {"goodbye":"that"}'

.length

list.length;

Returns the length of the list.

list.push('one');
list.push('two');
list.push('three');
console.log(list.length); // 3

Changelog

  • 2.1.x - 2/08/2015:
    • + # add (2.1.0)
    • + # add tests (2.1.0)
    • + # remove (2.1.0)
    • + # remove tests (2.1.0)
    • + # toString (2.1.0)
    • + # toString tests (2.1.0)
    • Add new functions to documentation. (2.1.0)
    • Reorder documentation. (2.1.0)
    • Change internal workings: (2.1.0)
      • 'Private' findNode function, and refactor methods to use it
      • Change node creation to add data in constructor
      • Reorder functions
  • 2.0.x - 31/07/2015:
    • Add some keywords to the package.json. (2.0.2)
    • Edit formatting of changelog. (2.0.2)
    • Make the get function faster by implementing back to front search. (2.0.1)
    • + # get (2.0.0)
    • + # get tests (2.0.0)
    • Return undefined if the data doesn't exist instead of null. (2.0.0)
    • Add get function to the documentation. (2.0.0)
  • 1.1.x - 30/07/2015:
    • Add navigation to the README. (1.1.3)
    • Small change to some errors in the README. (1.1.2)
    • Add unShift function to the documentation. (1.1.1)
    • + # unShift (1.1.0)
    • + # unShift tests (1.1.0)
  • 1.0.x - 30/07/2015:
    • Rename all function names: (1.0.0)
      • # add -> # push
      • # removeFromStart -> # shift
      • # removeFromEnd -> # pop
      • # getStart -> # first
      • # getEnd -> # last
    • Update the README formatting and information within.
  • 0.1.x - 30/07/2015:
    • Added git remotes and issues to the package.json. (0.1.1)
    • Initial implementation with: (0.1.0)
      • Constructor
      • # add
      • # removeFromStart
      • # removeFromEnd
      • # getStart
      • # getEnd
      • .length
      • Passing tests
  • 0.0.x - 30/07/2015 - Initial publish with no contents. (0.0.0)