Created
October 14, 2025 18:54
-
-
Save guilhermepontes/5e2961c8525124f2f2941b6a9dafebd5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { | |
#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