|
1 | 1 | # Instructions |
2 | 2 |
|
3 | | -Your task is to build a stopwatch that can be used to keep track of lap times. |
4 | | -The stopwatch has the following functionality: |
| 3 | +Your task is to build a stopwatch to keep precise track of lap times. |
5 | 4 |
|
6 | | -- Start: start/resume time tracking |
7 | | -- Stop: stop/pause time tracking |
8 | | -- Current lap: retrieve the time tracked for the current lap |
9 | | -- Previous laps: retrieve the previously recorded lap times |
10 | | -- Reset: stop time tracking, reset the current lap, and clear all previously recorded laps |
11 | | -- Lap: add the current lap time to the previous laps, then reset the current lap time and continue tracking time |
| 5 | +The stopwatch uses four commands (Start, Stop, Lap, and Reset) to keep track of two things: |
12 | 6 |
|
13 | | -You can think of a stopwatch as being in one of three states: |
| 7 | +1. The current lap's tracked time |
| 8 | +2. Any previously recorded lap times |
14 | 9 |
|
15 | | -1. Ready |
| 10 | +What commands can be used depends on which state the stopwatch is in: |
| 11 | + |
| 12 | +1. Ready (initial state) |
16 | 13 | 2. Running (tracking time) |
17 | 14 | 3. Stopped (not tracking time) |
18 | 15 |
|
19 | | -This is a visualization of the states (between square brackets) and the commands (between angular brackets): |
| 16 | +| Command | Begin state | End state | Effect | |
| 17 | +| ------- | ----------- | --------- | ----------------------------------------------------------- | |
| 18 | +| Start | Ready | Running | Start tracking time | |
| 19 | +| Start | Stopped | Running | Resume tracking time | |
| 20 | +| Stop | Running | Stopped | Stop tracking time | |
| 21 | +| Lap | Running | Running | Add current lap to previous laps and then reset current lap | |
| 22 | +| Reset | Stopped | Ready | Reset current lap and clear previous laps | |
20 | 23 |
|
21 | | -```text |
22 | | - <lap> |
23 | | - +-----+ |
24 | | - | | |
25 | | - <start> v | <stop> |
26 | | -[Ready] ---------> [Running] --------> [Stopped] |
27 | | - ^ ^ | | |
28 | | - | | <start> | | |
29 | | - | +------------------------+ | |
30 | | - | | |
31 | | - | <reset> | |
32 | | - +-----------------------------------------+ |
33 | | -``` |
| 24 | +TODO: add example of flow |
0 commit comments