Skip to content

Commit 29a88dc

Browse files
committed
refactor: removed if statement from peek()
1 parent 307239a commit 29a88dc

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

lesson_12/structs_ts/src/stack.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,10 @@ export class Stack {
2323
}
2424

2525
peek(): number | null {
26-
if (this.top === null) {
26+
if (this.top === undefined) {
2727
throw new Error('Empty List');
2828
}
29-
if (this.top !== undefined) {
30-
return this.top.val;
31-
}
32-
throw new Error('Empty List');
29+
return this.top.val;
3330
}
3431

3532
isEmpty(): boolean {

0 commit comments

Comments
 (0)