Skip to content

Instantly share code, notes, and snippets.

@setkyar
Created February 28, 2018 03:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save setkyar/6d6ddd706e5cc0802898ad1bbaa4560d to your computer and use it in GitHub Desktop.
Save setkyar/6d6ddd706e5cc0802898ad1bbaa4560d to your computer and use it in GitHub Desktop.
Stacks (Solution)
var Stack = function(){
this.storage = {};
this.count = 0;
};
Stack.prototype.push = function(val) {
this.storage[this.count++] = val;
return this.count;
}
Stack.prototype.pop = function() {
var value = this.storage[--this.count];
delete this.storage[this.count];
if (this.count < 0) {
this.count = 0;
}
return value;
}
Stack.prototype.size = function() {
return this.count;
}
var myWeeklyMenu = new Stack();
myWeeklyMenu.push("Coffee");
myWeeklyMenu.push("Rice");
myWeeklyMenu.push("Cold Drink");
myWeeklyMenu.pop();
myWeeklyMenu.size();
@setkyar
Copy link
Author

setkyar commented Feb 28, 2018

Please feel free to ask me about my answer gist. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment