| 1 | class MinStack { |
| 2 | constructor() { |
| 3 | this.elements = []; |
| 4 | this.mins = []; |
| 5 | this.min = undefined; |
| 6 | } |
| 7 | |
| 8 | push(element) { |
| 9 | this.elements.push(element); |
| 10 | if (element < this.min || this.min === undefined) { |
| 11 | this.min = element; |
| 12 | this.mins.push(element); |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | pop() { |
| 17 | if (this.elements.length > 0) { |
| 18 | const elementToPop = this.elements.pop(); |
| 19 | if (elementToPop === this.min) { |
| 20 | this.mins.pop(); |
| 21 | this.min = this.mins[this.mins.length - 1]; |
| 22 | } |
| 23 | return elementToPop; |
| 24 | } |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | const myMinStack = new MinStack(); |
| 29 |
nothing calls this directly
no outgoing calls
no test coverage detected