Creates a stack. Mutable. Use StackImmutable for an immutable alternative.
// Createconst s = new StackMutable();// Add one or more itemss.push(1, 2, 3, 4);// See what's on tops.peek; // 4// Remove the top-most, and return its.pop(); // 4// Now there's a new top-most elements.peek; // 3 Copy
// Createconst s = new StackMutable();// Add one or more itemss.push(1, 2, 3, 4);// See what's on tops.peek; // 4// Remove the top-most, and return its.pop(); // 4// Now there's a new top-most elements.peek; // 3
Readonly
True if stack is empty
True if stack is at its capacity. False if not, or if there is no capacity.
Number of items in stack
Get the item at the top of the stack without removing it (like pop would do)
pop
Item at the top of the stack, or undefined if empty.
Enumerates stack from bottom-to-top
Enumerates stack from top-to-bottom
Remove and return item from the top of the stack, or undefined if empty. If you just want to find out what's at the top, use peek.
Push data onto the stack. If toAdd is empty, nothing happens
toAdd
Rest
Data to add
Length of stack
Creates a stack. Mutable. Use StackImmutable for an immutable alternative.
Example: Basic usage