Created
October 17, 2016 10:12
-
-
Save tcstory/5a68cfab0c793ef9aab600e7824e5551 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Stack { | |
constructor() { | |
this._items = []; | |
} | |
push(element) { | |
if (Array.isArray(element)) { | |
this._items.push(...element); | |
} else { | |
this._items.push(element); | |
} | |
} | |
pop() { | |
return this._items.pop(); | |
} | |
peek() { | |
return this._items[this._items.length - 1]; | |
} | |
isEmpty() { | |
return this._items.length === 0; | |
} | |
get size() { | |
return this._items.length; | |
} | |
clear() { | |
this._items = []; | |
} | |
print() { | |
console.log(this._items.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment