|
1 | 1 | // This is the latest solution to the problem from the prep. |
2 | 2 | // Make sure to do the prep before you do the coursework |
3 | | -// Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. |
| 3 | +// |
| 4 | +// function formatAs12HourClock(time) { |
| 5 | +// const hours = Number(time.slice(0, 2)); |
| 6 | +// if (hours > 12) { |
| 7 | +// return `${hours - 12}:00 pm`; |
| 8 | +// } |
| 9 | +// return `${time} am`; |
| 10 | +// } |
4 | 11 |
|
5 | | -function formatAs12HourClock(time) { |
6 | | - const hours = Number(time.slice(0, 2)); |
7 | | - if (hours > 12) { |
8 | | - return `${hours - 12}:00 pm`; |
9 | | - } |
10 | | - return `${time} am`; |
11 | | -} |
12 | | - |
13 | | -const currentOutput = formatAs12HourClock("08:00"); |
14 | | -const targetOutput = "08:00 am"; |
15 | | -console.assert( |
16 | | - currentOutput === targetOutput, |
17 | | - `current output: ${currentOutput}, target output: ${targetOutput}` |
18 | | -); |
| 12 | +// const currentOutput = formatAs12HourClock("08:00"); |
| 13 | +// const targetOutput = "08:00 am"; |
| 14 | +// console.assert( |
| 15 | +// currentOutput === targetOutput, |
| 16 | +// `current output: ${currentOutput}, target output: ${targetOutput}` |
| 17 | +// ); |
19 | 18 |
|
20 | | -const currentOutput2 = formatAs12HourClock("23:00"); |
21 | | -const targetOutput2 = "11:00 pm"; |
22 | | -console.assert( |
23 | | - currentOutput2 === targetOutput2, |
24 | | - `current output: ${currentOutput2}, target output: ${targetOutput2}` |
25 | | -); |
26 | | -const currentOutput3=formatAs12HourClock("00:00"); |
27 | | -const targetOutput3="12:00 am"; |
28 | | -console.assert(currentOutput3===targetOutput3, |
29 | | - `current output: ${currentOutput3}, target output: ${targetOutput3}` |
30 | | -) |
31 | | -const currentOutput4=formatAs12HourClock("12:00"); |
32 | | -const targetOutput4="12:00 pm"; |
33 | | -console.assert(currentOutput4===targetOutput4, |
34 | | - `current output: ${currentOutput4}, target output: ${targetOutput4}` |
35 | | -) |
| 19 | +// const currentOutput2 = formatAs12HourClock("23:00"); |
| 20 | +// const targetOutput2 = "11:00 pm"; |
| 21 | +// console.assert( |
| 22 | +// currentOutput2 === targetOutput2, |
| 23 | +// `current output: ${currentOutput2}, target output: ${targetOutput2}` |
| 24 | +// ); |
| 25 | +// const currentOutput3=formatAs12HourClock("00:00"); |
| 26 | +// const targetOutput3="12:00 am"; |
| 27 | +// console.assert(currentOutput3===targetOutput3, |
| 28 | +// `current output: ${currentOutput3}, target output: ${targetOutput3}` |
| 29 | +// ) |
| 30 | +// const currentOutput4=formatAs12HourClock("12:00"); |
| 31 | +// const targetOutput4="12:00 pm"; |
| 32 | +// console.assert(currentOutput4===targetOutput4, |
| 33 | +// `current output: ${currentOutput4}, target output: ${targetOutput4}` |
| 34 | +// ) |
36 | 35 |
|
37 | 36 |
|
38 | 37 | // This is my version |
@@ -84,6 +83,13 @@ console.assert( |
84 | 83 |
|
85 | 84 | currentTime = TimeAs12hours("00:00"); |
86 | 85 | targetTime = "12:00 am"; |
| 86 | +console.assert( |
| 87 | + currentTime === targetTime, |
| 88 | + `current time:${currentTime}, Target Time:${targetTime}` |
| 89 | +); |
| 90 | + |
| 91 | +currentTime=TimeAs12hours("12:00"); |
| 92 | +targetTime="12:00 pm"; |
87 | 93 | console.assert( |
88 | 94 | currentTime === targetTime, |
89 | 95 | `current time:${currentTime}, Target Time:${targetTime}` |
|
0 commit comments