Skip to content

Instantly share code, notes, and snippets.

@guilhermepontes
Created October 14, 2025 18:54
Show Gist options
  • Save guilhermepontes/5e2961c8525124f2f2941b6a9dafebd5 to your computer and use it in GitHub Desktop.
Save guilhermepontes/5e2961c8525124f2f2941b6a9dafebd5 to your computer and use it in GitHub Desktop.
class Stack {
#stack = [];
push(item) {
this.#stack.unshift(item);
return this;
}
peep() {
return this.#stack;
}
size() {
return this.#stack.length;
}
isEmpty() {
return this.#stack.length === 0;
}
empty() {
this.#stack = [];
}
pop() {
this.#stack = this.#stack.slice(1);
}
head() {
return this.#stack[0];
}
tail() {
return this.#stack[this.#stack.length - 1];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment