🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

double-ended-queue

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
d

double-ended-queue

Extremely fast double-ended queue implementation

2.1.0-0
latest
100

Supply Chain Security

100

Vulnerability

100

Quality

76

Maintenance

100

License

Version published
Weekly downloads
415K
-19.81%
Maintainers
1
Weekly downloads
 
Created
Issues
15

What is double-ended-queue?

The double-ended-queue npm package provides a highly optimized implementation of a double-ended queue (deque), which allows for efficient addition and removal of elements from both ends of the queue. This data structure is useful for various applications such as task scheduling, caching, and more.

What are double-ended-queue's main functionalities?

Add elements to the front

This feature allows you to add elements to the front of the deque. The `unshift` method is used to add elements to the front.

const Deque = require('double-ended-queue');
const deque = new Deque();
deque.unshift(1);
deque.unshift(2);
console.log(deque.toArray()); // Output: [2, 1]

Add elements to the back

This feature allows you to add elements to the back of the deque. The `push` method is used to add elements to the back.

const Deque = require('double-ended-queue');
const deque = new Deque();
deque.push(1);
deque.push(2);
console.log(deque.toArray()); // Output: [1, 2]

Remove elements from the front

This feature allows you to remove elements from the front of the deque. The `shift` method is used to remove elements from the front.

const Deque = require('double-ended-queue');
const deque = new Deque();
deque.push(1);
deque.push(2);
console.log(deque.shift()); // Output: 1
console.log(deque.toArray()); // Output: [2]

Remove elements from the back

This feature allows you to remove elements from the back of the deque. The `pop` method is used to remove elements from the back.

const Deque = require('double-ended-queue');
const deque = new Deque();
deque.push(1);
deque.push(2);
console.log(deque.pop()); // Output: 2
console.log(deque.toArray()); // Output: [1]

Access elements by index

This feature allows you to access elements by their index in the deque. The `get` method is used to retrieve elements by index.

const Deque = require('double-ended-queue');
const deque = new Deque();
deque.push(1);
deque.push(2);
console.log(deque.get(0)); // Output: 1
console.log(deque.get(1)); // Output: 2

Other packages similar to double-ended-queue

FAQs

Package last updated on 05 Jan 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts