GithubHelp home page GithubHelp logo

cesarvr / deque-js Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 6 KB

JS Port of Python Deques. Deques are a generalization of stacks and queues (the name is pronounced “deck” and is short for “double-ended queue”).

JavaScript 100.00%

deque-js's Introduction

Deque

this is just a implementation of Python deques in JS. Deques are a generalization of stacks and queues (the name is pronounced “deck” and is short for “double-ended queue”).

Though list objects support similar operations, they are optimized for fast fixed-length operations and incur O(n) memory movement costs for pop(0) and insert(0, v) operations which change both the size and position of the underlying data representation.

Install

npm install dqs 

Usage

let dqueue = require('dqs')

## Methods

insert(x)

Add x to the right side of the deque.

all

Return all the objects in an Array.

clear()

Remove all elements from the deque leaving it with length 0.

count(x)

Count the number of deque elements equal to x.

pop()

Remove and return an element from the right side of the deque. If no elements are present, raises an IndexError.

popleft()

Remove and return an element from the left side of the deque. If no elements are present, raises an IndexError.

let dq = new DQueue([2,3,0,1])
let v1 = dq.popLeft()
let v2 = dq.popLeft()

console.log(v1, v2) // 2 3
console.log(dq.all()) // [0,1]

rotate(n=1)

Rotate the deque n steps to the right. If n is negative, rotate to the left.

let dqueue = new DQS([2,3,0,1])
dqueue.rotate(-2)
//[0,1,2,3]

When the deque is not empty, rotating one step to the right is equivalent to d.appendleft(d.pop()), and rotating one step to the left is equivalent to d.append(d.popleft()).

deque-js's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.