|
1 | 1 | export default class UndergroundSystem {
|
2 |
| - id2info = new Map<number, [string, number]>(); |
3 |
| - station2time = new Map<string, number[]>(); |
| 2 | + #id2info = new Map<number, [string, number]>(); |
| 3 | + #station2time = new Map<string, number[]>(); |
4 | 4 | constructor() {
|
5 | 5 | }
|
6 | 6 |
|
7 | 7 | checkIn(id: number, stationName: string, t: number): void {
|
8 | 8 | const info: [string, number] = [stationName, t];
|
9 |
| - this.id2info.set(id, info); |
| 9 | + this.#id2info.set(id, info); |
10 | 10 | }
|
11 | 11 |
|
12 | 12 | checkOut(id: number, stationName: string, t: number): void {
|
13 |
| - const info = this.id2info.get(id); |
| 13 | + const info = this.#id2info.get(id); |
14 | 14 | if (info) {
|
15 | 15 | const key = JSON.stringify([info[0], stationName]);
|
16 |
| - const time = this.station2time.get( |
| 16 | + const time = this.#station2time.get( |
17 | 17 | key,
|
18 | 18 | ) ?? [];
|
19 | 19 | time.push(t - info[1]);
|
20 |
| - this.station2time.set(key, time); |
| 20 | + this.#station2time.set(key, time); |
21 | 21 | } else {
|
22 | 22 | throw Error("accident");
|
23 | 23 | }
|
24 | 24 | }
|
25 | 25 |
|
26 | 26 | getAverageTime(startStation: string, endStation: string): number {
|
27 | 27 | const key = JSON.stringify([startStation, endStation]);
|
28 |
| - const time = this.station2time.get( |
| 28 | + const time = this.#station2time.get( |
29 | 29 | key,
|
30 | 30 | );
|
31 | 31 | if (!time) throw Error("accident");
|
|
0 commit comments