Skip to content

Commit 58517aa

Browse files
author
Bianca Elizabeth
authored
Merge pull request #10 from li-xinyang/patch-1
fix: Handle pop empty stack
2 parents 22e8f8c + 6416d81 commit 58517aa

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

data-structures/stack.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ Stack.prototype.push = function(value) {
6767

6868
// O(1)
6969
Stack.prototype.pop = function() {
70+
if (this._count === 0) {
71+
return 'No element inside the stack. Add element before poping.'
72+
}
73+
7074
var value = this._storage[--this._count];
7175
delete this._storage[this._count];
7276
if (this._count < 0) {

0 commit comments

Comments
 (0)