|
1 | 1 | export class SplitSecondStopwatch { |
2 | 2 | constructor() { |
3 | | - this._state = 'ready'; |
4 | | - this._totalSeconds = 0; |
5 | | - this._currentLap = 0; |
6 | | - this._previousLaps = []; |
| 3 | + throw new Error('Remove this line and implement the function'); |
7 | 4 | } |
8 | 5 |
|
9 | 6 | get state() { |
10 | | - return this._state; |
| 7 | + throw new Error('Remove this line and implement the function'); |
11 | 8 | } |
12 | 9 |
|
13 | 10 | get currentLap() { |
14 | | - return this._formatTime(this._currentLap); |
| 11 | + throw new Error('Remove this line and implement the function'); |
15 | 12 | } |
16 | 13 |
|
17 | 14 | get total() { |
18 | | - return this._formatTime(this._totalSeconds); |
| 15 | + throw new Error('Remove this line and implement the function'); |
19 | 16 | } |
20 | 17 |
|
21 | 18 | get previousLaps() { |
22 | | - return this._previousLaps.map((s) => this._formatTime(s)); |
| 19 | + throw new Error('Remove this line and implement the function'); |
23 | 20 | } |
24 | 21 |
|
25 | 22 | start() { |
26 | | - if (this._state === 'running') { |
27 | | - throw new Error('cannot start an already running stopwatch'); |
28 | | - } |
29 | | - this._state = 'running'; |
| 23 | + throw new Error('Remove this line and implement the function'); |
30 | 24 | } |
31 | 25 |
|
32 | 26 | stop() { |
33 | | - if (this._state !== 'running') { |
34 | | - throw new Error('cannot stop a stopwatch that is not running'); |
35 | | - } |
36 | | - this._state = 'stopped'; |
| 27 | + throw new Error('Remove this line and implement the function'); |
37 | 28 | } |
38 | 29 |
|
39 | 30 | lap() { |
40 | | - if (this._state !== 'running') { |
41 | | - throw new Error('cannot lap a stopwatch that is not running'); |
42 | | - } |
43 | | - this._previousLaps.push(this._currentLap); |
44 | | - this._currentLap = 0; |
| 31 | + throw new Error('Remove this line and implement the function'); |
45 | 32 | } |
46 | 33 |
|
47 | 34 | reset() { |
48 | | - if (this._state !== 'stopped') { |
49 | | - throw new Error('cannot reset a stopwatch that is not stopped'); |
50 | | - } |
51 | | - this._state = 'ready'; |
52 | | - this._totalSeconds = 0; |
53 | | - this._currentLap = 0; |
54 | | - this._previousLaps = []; |
| 35 | + throw new Error('Remove this line and implement the function'); |
55 | 36 | } |
56 | 37 |
|
57 | 38 | advanceTime(duration) { |
58 | | - if (this._state === 'running') { |
59 | | - const seconds = this._toSeconds(duration); |
60 | | - this._currentLap += seconds; |
61 | | - this._totalSeconds += seconds; |
62 | | - } |
63 | | - } |
64 | | - |
65 | | - _toSeconds(duration) { |
66 | | - const [h, m, s] = duration.split(':').map(Number); |
67 | | - return h * 3600 + m * 60 + s; |
68 | | - } |
69 | | - |
70 | | - _formatTime(seconds) { |
71 | | - const h = Math.floor(seconds / 3600); |
72 | | - const m = Math.floor((seconds % 3600) / 60); |
73 | | - const s = seconds % 60; |
74 | | - |
75 | | - return `${String(h).padStart(2, '0')}:${String(m).padStart(2, '0')}:${String(s).padStart(2, '0')}`; |
| 39 | + throw new Error('Remove this line and implement the function'); |
76 | 40 | } |
77 | 41 | } |
0 commit comments