Skip to content

Instantly share code, notes, and snippets.

@giovanisleite
Created July 25, 2021 20:48
Show Gist options
  • Save giovanisleite/d8410bfb031880787c797a1232b77850 to your computer and use it in GitHub Desktop.
Save giovanisleite/d8410bfb031880787c797a1232b77850 to your computer and use it in GitHub Desktop.
Data Structure: Stack
class Stack {
constructor() {
this.stack = [];
}
get length() {
return this.stack.length;
}
push(el) {
this.stack.push(el);
}
pop() {
return this.stack.pop()
}
peek() {
if(this.isEmpty()) {
return undefined
}
return this.stack[this.length - 1]
}
isEmpty() {
return this.length === 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment