Coder Social home page Coder Social logo

deque's Introduction

Deque

NPM version NPM downloads Build status Test coverage

Deques are a generalization of stacks and queues (the name is pronounced "deck" and is short for "double-ended queue"). -- Python collections.

Installation

npm install @blakeembrey/deque --save

Usage

  • size Returns the number of elements in the deque.
  • push(x) Add x to right side of the deque.
  • pushLeft(x) Add x to the left side of the deque.
  • clear() Remove all elements from the deque leaving it with length 0.
  • extend(iterable) Extend the right side of the deque by appending elements from iterable.
  • extendLeft(iterable) Extend the left side of the deque by appending elements from iterable.
  • peek(i) Return the element at index i in the deque.
  • indexOf(x, start?) Return the position of x in the deque.
  • has(x) Return a boolean indicating whether x is in the deque.
  • insert(i, x) Insert x into the deque at position i.
  • pop() Remove and return an element from the right side of the deque. If no elements are present, throws RangeError.
  • popLeft() Return and return an element from the left side of the deque. If no elements are present, throws RangeError.
  • delete(i) Delete the value at position i.
  • reverse() Reverse the elements of the deque in-place.
  • rotate(n=1) Rotate the deque n steps to the right.
  • entries() Return an iterable of deque.
  • @@iterator() Return an iterable of deque.
import { Deque } from '@blakeembrey/deque'

const d = new Deque('ghi')

for (const value of d) {
  console.log(value.toUpperCase()) //=> G H I
}

d.push('j')
d.pushLeft('f')
d //=> Deque(['f', 'g', 'h', 'i', 'j'])

d.pop() //=> 'j'
d.popLeft() //=> 'f'

Array.from(d) //=> ['g', 'h', 'i']

d.peek(0) //=> 'g'
d.peek(-1) //=> 'i'

d.extend('jkl')
d //=> Deque(['g', 'h', 'i', 'j', 'k', 'l'])

d.rotate(1)
d //=> Deque(['l', 'g', 'h', 'i', 'j', 'k'])

d.rotate(-1)
d //=> Deque(['g', 'h', 'i', 'j', 'k', 'l'])

const d2 = new Deque(d)

d2 //=> Deque(['g', 'h', 'i', 'j', 'k', 'l'])

TypeScript

This project uses TypeScript and publishes definitions on NPM.

Reference

Circular array implementation originally based on denque with additional optimizations.

License

Apache 2.0

deque's People

Contributors

blakeembrey avatar dependabot[bot] avatar maxdeviant avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.