```js
function MinStack() {
this.stack = []
this.helpStack = []
this.min = Infinity
}
MinStack.prototype.push = function(item) {
this.stack.push(item)
this.min = this.min > item ? item : this.min
this.helpStack.push(this.min)
}
MinStack.prototype.pop = function() {
const item = this.stack.pop()
//如果删了stack里面的最小值,就需要删除helpStack里面所有的最小值,while循环删除
while (this.min === item) {
this.min = this.helpStack.pop()
}
return item
}
MinStack.prototype.getMin = function() {
return this.min
}
const s = new MinStack()
const arr = [3]
arr.map(item => s.push(item))
console.log(s)
while (s.stack.length) {
let res = s.pop()
console.log(res, s.getMin())
}
```