A simple stack data structure provided as es2015 module.
As npm for Node.js:
$ npm install stack-es2015-module --save
Or download the bundle file.
$ npm run-script build
creates the bundle file in the dist
folder.
As npm package:
$ npm test
import Stack from 'stack-es2015-module';
let stack = new Stack();
stack.push(42);
stack.push(17);
stack.top(); // 17
stack.pop();
stack.top(); // 42
stack.withElement(33, () => {
stack.top(); // 33
});
Initializes a new empty Stack
.
Returns the top element of the stack.
Pops the top element of the stack.
Pushes the element
at the top of the stack.
Pushes the element
at the top of the stack and executes the callback
with the optional context
.
After successfully returning from the callback
or upon an uncatched error, the top element is poped from the stack.
MIT