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 🙏

© 2025 – Pkg Stats / Ryan Hefner

linked-deque

v1.0.4

Published

A simple double-ended queue.

Downloads

56

Readme

Linked-Deque

A deque (double-ended queue) provides fast pushing and popping from both sides of the data structure.
This implementation is a simple deque built off of a doubly linked list.

The Symbol.iterator method is defined to allow for the use of a for ... of loop on the deque.
Additionally, there is a length property used to access the current size of the deque in O(1) time.

All methods will have the time complexity listed in their documentation.

Install

npm install --save linked-deque

Deque( iterable )

  • Constructor for the deque with an optional param of any object that implements Symbol.iterator.
    The deque will be initialized with all the elements of the iterable. (if one is given) O(n)

Methods

push( value )

  • Add an element to the back (right side) of the deque. O(1)

pushLeft( value )

  • Add an element to the front (left side) of the deque. O(1)

getHead( )

  • Get the first element in the deque (the front element) without removing it.
    Returns null if the deque is empty. O(1)

getTail( )

  • Get the last element in the deque (the back element) without removing it.
    Returns null if the deque is empty. O(1)

at( index )

  • Get an element from the deque using an order-based index.
    Throws a RangeError with an invalid index. O(n/2)

pop( )

  • Remove and return the last element in the deque.
    If the deque is empty, it returns null. O(1)

popLeft( )

  • Remove and return the first element in the deque.
    If the deque is empty, it returns null. O(1)

insertAt( value, index )

  • Add an element to the deque at the specified index.
    Throws a RangeError with an invalid index.
    Returns a bool indicating success or failure. O(n/2)

removeAt( index )

  • Remove and return the element at the specified index in the deque.
    Throws a RangeError if the index is invalid. O(n/2)

reverse( )

  • Reverse the order of elements in the deque in-place. O(n)

rotate( steps=1 )

  • Rotate the deque to the right by the given number of steps. (One by default.)
    If the number is negative rotate to the left.
    Based on the input, the method will always calculate the optimal direction
    and number of steps to rotate the deque.
    For example: if the given number of steps equals the length of the deque,
    nothing will happen. O(n/2)

copy( )

  • Create and return a shallow copy of the deque. O(n)

clear( )

  • Remove all elements from the deque resulting in a length of 0. O(1)

toArray( )

  • Get an Array of all the elements in the deque. O(n)

toString( )

  • Get a String of all the elements in the deque for the purpose of printing. O(n)

Usage

import Deque from "linked-deque"; 

const deque = new Deque([1, 2, 3]); // ( 1 ) -> ( 2 ) -> ( 3 ) -> null

deque.popLeft(); // ( 2 ) -> ( 3 ) -> null

deque.pushLeft(5); // ( 5 ) -> ( 2 ) -> ( 3 ) -> null

deque.length; // 3

deque.rotate(); // ( 3 ) -> ( 5 ) -> ( 2 ) -> null

deque.insertAt("foo", 1); // ( 3 ) -> ( "foo" ) -> ( 5 ) -> ( 2 ) -> null

deque.removeAt(2); // ( 3 ) -> ( "foo" ) -> ( 2 ) -> null

deque.reverse(); // ( 2 ) -> ( "foo" ) -> ( 3 ) -> null

deque.push(7); // ( 2 ) -> ( "foo" ) -> ( 3 ) -> ( 7 ) -> null


// you can use for ... of loops 
for (let element of deque) {
    // do something
}


deque.clear(); // null

deque.length; // 0