Created
December 6, 2017 22:05
-
-
Save johnfoderaro/d64d2a203ede285655c8d269e21a43cc to your computer and use it in GitHub Desktop.
ES6+ Stack Class Implementation
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) { | |
this.items.push(element); | |
} | |
pop() { | |
return this.items.pop(); | |
} | |
peek() { | |
return this.items[items.length - 1]; | |
} | |
isEmpty() { | |
return this.items.length === 0; | |
} | |
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