Skip to content

Commit

Permalink
Merge pull request #10 from li-xinyang/patch-1
Browse files Browse the repository at this point in the history
fix: Handle pop empty stack
  • Loading branch information
Bianca Elizabeth authored Jun 25, 2017
2 parents 22e8f8c + 6416d81 commit 58517aa
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions data-structures/stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ Stack.prototype.push = function(value) {

// O(1)
Stack.prototype.pop = function() {
if (this._count === 0) {
return 'No element inside the stack. Add element before poping.'
}

var value = this._storage[--this._count];
delete this._storage[this._count];
if (this._count < 0) {
Expand Down

0 comments on commit 58517aa

Please sign in to comment.