stackjs

a simple stack data structure

stack.js

A simple stack data structure for Node.js and the browser.

As component for the browser:

$ component install janogonzalez/stackjs

As npm for Node.js:

$ npm install stackjs
var Stack = require('stackjs');
 
var stack = new Stack();
 
stack.push(10);
stack.push(5);
stack.size(); // 2 
stack.peek(); // 5 
stack.pop(); // 5 
stack.size(); // 1 

Initializes a new empty Stack.

Returns whether the stack is empty or not.

Peeks at the top element of the stack. Throws an Error when the stack is empty.

Pops the top element of the stack. Throws an Error when the stack is empty.

Pushes the element at the top of the stack and returns its new size.

Returns the size of the stack.

As component in the browser, open test/test.html in your browser:

$ make
$ open test/test.html

As npm package:

$ npm test

MIT