Skip to content

Commit 82edf1c

Browse files
committed
fix: extra credit stack.ts
1 parent e658f2e commit 82edf1c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lesson_12/structs_ts/src/stack.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ export class Stack {
2020
}
2121

2222
peek(): number | null {
23+
if (this.top === undefined) {
24+
throw new Error('is Empty');
25+
}
2326
return this.top ? this.top.val : null;
2427
}
25-
2628
isEmpty(): boolean {
2729
return this.top === undefined;
2830
}

0 commit comments

Comments
 (0)