Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

slim-stack

nivrith22MIT1.3.0TypeScript support: included

stack implementation for JavaScript

stack, create-stack, stackjs, js-stack, slim-stack, queue, first-in-last-out

readme

slim-stack

CircleCI NPM Downloads node License MIT

stack implementation for JavaScript

Highlights

  • Written in Typescript

  • Iterable using for...of statement

  • follows LIFO model (Last in first out)

  • Iterate top to bottom

Usage

stack implementation for JavaScript


  import SlimStack from 'slim-stack';

  // Empty stack
  let stack = new SlimStack(); //creates empty stack

  stack.push(6); // Pushes 6 to top of the stack
  stack.pop(); // Removes the top most element of the stack and returns it
  stack.peek(); // Returns the top most element of the stack without removing it
  stack.size(); // Returns the size of the stack

  // Or create a stack from an array
  // last element of array will be top most element of the stack

  stack = new SlimStack([1,2,3,4,5]);

  stack.push(6);
  stack.pop(); // returns 6
  stack.peek(); // returns 5
  stack.size(); // returns 5

  ### Iteration

  Slim Stack follows the iterator and iterable protocols making it an iterable type. Which means you can use
  the for...of statement to iterate over elements of  the stack from top to bottom.

  for (let item of stack) {
    console.log(item);
  }

  //5
  //4
  //3
  //2
  //1

License

MIT © Nivrith

changelog

Changelog

All notable changes to this project will be documented in this file. Dates are displayed in UTC.

Generated by auto-changelog.

v1.3.0

20 July 2019

v1.2.3

15 July 2019

  • Cleanup readme and package.json bc0fe3f

v1.1.0

14 July 2019

v1.0.3

14 July 2019

v1.0.2

13 July 2019

v1.0.1

13 July 2019

v1.0.0

13 July 2019