Skip to content

Conversation

gautam-paladiya
Copy link

…out calculating length

@sudheerj
Copy link
Owner

@gautam-paladiya Thanks for your PR. Let's use a standway to access the array item.

peek() {
// Check if the stack is empty
if (this.isEmpty()) {
throw new Error("Stack Underflow: Cannot peek from an empty stack");
}
// Return the top most element from the stack without removing it
return this.array[this.array.length - 1];
}

@gautam-paladiya
Copy link
Author

Accepted please go ahead

@sudheerj
Copy link
Owner

Fixed with a manual change

@sudheerj sudheerj closed this Apr 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants