You are on page 1of 1

Stack

var Stack = function(){


this.storage = ''
}

Stack.prototype.push = function(val) {
this.storage = this.storage.concat('-', val) // hello-hel-hi
}

Stack.prototype.pop = function() {
var str = this.storage.slice(this.storage.lastIndexOf('-') + 1)
this.storage = this.storage.substring(0, this.storage.lastIndexOf('-'))
console.log(str)
};

Stack.prototype.size = function() {
console.log(this.storage.split('-').length-1)
};

var myWeeklyMenu = new Stack();

myWeeklyMenu.push("Monday")
myWeeklyMenu.push('Tuesday')
myWeeklyMenu.push('mcdsmlcsk')

myWeeklyMenu.pop();
myWeeklyMenu.size();

You might also like