0.0.5 • Published 8 years ago

dastack v0.0.5

Weekly downloads
6
License
MIT
Repository
github
Last release
8 years ago

dastack Build Status

All of the implementations of stacks I found attached everything to the prototype and didn't make good use of private encapsulation, getters, non-enumerable methods, etc.

So here it is, a clean implementation of a stack written in straight simple es5.

API

Create a stack

var createStack = require('dastack');

var stack = createStack(); // => Creates an empty stack

var stack = createStack(1, 2, 3); // => Creates a stack with initial values

stack.size

The only property on the stack is size, works exactly the same as the length property on Array.

var stack = createStack(1, 2, 3);

stack.size // => 3

stack.push()

Add a new element to the top of the stack.

var stack2 = createStack(1, 2, 3);

stack.size // => 3

stack.pop()

Remove the top element from the top of the stack.

var stack = createStack(1, 2, 3);

stack.pop() // => 3

stack.size // => 2

stack.peek()

Get the top element from the top of the stack, but do not remove it.

var stack = createStack(1, 2, 3);

stack.peek() // => 3

stack.size // => 3

stack.clear()

Empty the stack.

var stack = createStack(1, 2, 3);

stack.clear()

stack.size // => 0

stack.toString()

Get the current stack as a string.

var stack = createStack(1, 2, 3);

stack.toString() // => "1,2,3"

stack.toArray()

Copy the current stack into a regular array.

var stack = createStack(1, 2, 3);

stack.toArray() // => [1, 2, 3]
0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago