A Node.js JavaScript implementation of the stack data type. Supporting both LIFO via push()
and pop()
, and FIFO via push()
and shift()
.
npm install stack-list
new StackList(initialValue);
An Array
of values of any type to initially populate the stack list.
Push a new value to the top of the stack.
Take the top most value off the list and return it.
Take the bottom most value off the list and return it.
View the top most value on the list.
View the bottom most value on the list.
Reset to an empty list.
The number of elements in the list. Also available under alias property length
.
const StackList = require('stack-list');
let list = new StackList(['Hey']); // Optional initial values
// Push
list.push('Mate');
// Get size
list.size; // 2
// Peek top value
list.peek(); // 'Mate'
// Pop top value
list.pop(); // 'Mate'
list.pop(); // 'Hey'
// Clear stack
list.clear();