Skip to content

Commit 6175f1b

Browse files
author
AmiyahJo
committed
fix: peek() method in stack.ts
feat: new constant to store the current stack
1 parent 295e936 commit 6175f1b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lesson_12/structs_ts/src/stack.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export class Stack {
2727
if (this.isEmpty()) {
2828
return null;
2929
}
30-
31-
return this.top!.val;
30+
const currentTop = this.top;
31+
return currentTop ? currentTop.val : null;
3232
}
3333

3434
isEmpty(): boolean {

0 commit comments

Comments
 (0)