1
var StockSpanner = function () {6
StockSpanner.prototype.next = function (price) {7
// keep Pop-ing if top element of stack is bigger than current price9
this.stack.length > 0 &&10
this.stack[this.stack.length - 1][0] <= price15
// if stack is empty after above operation16
if (this.stack.length === 0) {17
// Push current price with index18
this.stack.push([price, this.idx]);20
// increment index - this is a tricky part26
// caclulate distance from top element of stack and return28
const res = this.idx - this.stack[this.stack.length - 1][1];29
this.stack.push([price, this.idx]);