Skip to content

Commit e6db549

Browse files
committed
fix: changed quotes and removed non-null assertions
1 parent 12bce4e commit e6db549

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

lesson_12/structs_ts/src/lesson12.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ export class Lesson12 {
2020
}
2121

2222
if (oddPoints > evenPoints) {
23-
return "Odd";
23+
return 'Odd';
2424
} else if (evenPoints > oddPoints) {
25-
return "Even";
25+
return 'Even';
2626
} else {
27-
return "Tie";
27+
return 'Tie';
2828
}
2929
}
3030
}

lesson_12/structs_ts/src/stack.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
import { ListNode } from './list_node.js';
22

33
export class Stack {
4-
private top: ListNode | null;
4+
private top: ListNode | undefined;
55

66
constructor() {
7-
this.top = null;
7+
this.top = undefined;
88
}
99

1010
push(value: number): void {
1111
const newNode = new ListNode(value);
12-
newNode.next = this.top !== null ? this.top : undefined;
12+
newNode.next = this.top;
1313
this.top = newNode;
1414
}
1515

1616
pop(): number | undefined {
17-
if (this.isEmpty()) {
18-
throw new Error('Stack is empty');
17+
if (this.top === undefined) {
18+
return undefined;
1919
}
20-
const value = this.top!.val;
21-
this.top = this.top!.next || null;
22-
return value;
20+
const poppedNode = this.top;
21+
this.top = this.top.next;
22+
return poppedNode.val;
2323
}
2424

2525
peek(): number | null {
26-
if (this.isEmpty()) {
26+
if (this.top === undefined) {
2727
throw new Error('Stack is empty');
2828
}
29-
return this.top!.val;
29+
return this.top.val;
3030
}
3131

3232
isEmpty(): boolean {
33-
return this.top === null;
33+
return this.top === undefined;
3434
}
3535
}

0 commit comments

Comments
 (0)