Skip to content

Commit f26433f

Browse files
committed
Fix stub
1 parent 45360a4 commit f26433f

1 file changed

Lines changed: 10 additions & 46 deletions

File tree

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,41 @@
11
export class SplitSecondStopwatch {
22
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');
74
}
85

96
get state() {
10-
return this._state;
7+
throw new Error('Remove this line and implement the function');
118
}
129

1310
get currentLap() {
14-
return this._formatTime(this._currentLap);
11+
throw new Error('Remove this line and implement the function');
1512
}
1613

1714
get total() {
18-
return this._formatTime(this._totalSeconds);
15+
throw new Error('Remove this line and implement the function');
1916
}
2017

2118
get previousLaps() {
22-
return this._previousLaps.map((s) => this._formatTime(s));
19+
throw new Error('Remove this line and implement the function');
2320
}
2421

2522
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');
3024
}
3125

3226
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');
3728
}
3829

3930
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');
4532
}
4633

4734
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');
5536
}
5637

5738
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');
7640
}
7741
}

0 commit comments

Comments
 (0)