slim-stack
stack implementation for JavaScript
Highlights
-
Written in Typescript
-
Iterable using for...of statement
-
follows LIFO model (Last in first out)
-
Iterate top to bottom
Usage
stack implementation for JavaScript
; // Empty stack let stack = ; //creates empty stack stack; // Pushes 6 to top of the stack stack; // Removes the top most element of the stack and returns it stack; // Returns the top most element of the stack without removing it stacksize; // Returns the size of the stack // Or create a stack from an array // last element of array will be top most element of the stack stack = 12345; stack; stack; // returns 6 stack; // returns 5 stacksize; // returns 5 ### Iteration Slim Stack follows the iterator and iterable protocols making it an iterable type Which means you can use the for...of statement to iterate over elements of the stack from top to bottom for let item of stack console; //5 //4 //3 //2 //1
License
MIT © Nivrith