Skip to content

Instantly share code, notes, and snippets.

@johnfoderaro
Created December 6, 2017 22:05
Show Gist options
  • Save johnfoderaro/d64d2a203ede285655c8d269e21a43cc to your computer and use it in GitHub Desktop.
Save johnfoderaro/d64d2a203ede285655c8d269e21a43cc to your computer and use it in GitHub Desktop.
ES6+ Stack Class Implementation
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