Skip to content

Commit

Permalink
fix: peek() method in stack.ts
Browse files Browse the repository at this point in the history
feat: new constant to store the current stack
  • Loading branch information
AmiyahJo committed Oct 23, 2024
1 parent 295e936 commit 6175f1b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lesson_12/structs_ts/src/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export class Stack {
if (this.isEmpty()) {
return null;
}

return this.top!.val;
const currentTop = this.top;
return currentTop ? currentTop.val : null;
}

isEmpty(): boolean {
Expand Down

0 comments on commit 6175f1b

Please sign in to comment.