Skip to content

Commit 525f9fc

Browse files
committed
ordered and structured my function
1 parent 68d0b4c commit 525f9fc

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

‎format-clock-edge-cases/timeConverter.js‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,29 @@ function formatAs12HourClock(time) {
22
const hours = Number(time.slice(0, 2));
33
const minutes = time.slice(3, 5);
44

5+
if (hours === 0) {
6+
return `12:${minutes} am`;
7+
}
8+
9+
if (hours === 12) {
10+
return `12:${minutes} pm`;
11+
}
12+
513
if (hours > 12) {
614
const time = hours - 12;
715

816
if (time < 10) {
917
return `0${time}:${minutes} pm`;
1018
}
19+
1120
return `${hours - 12}:${minutes} pm`;
1221
}
13-
if (hours === 0) {
14-
return `12:${minutes} am`;
15-
}
16-
if (hours === 12) {
17-
return `12:${minutes} pm`;
18-
}
1922

2023
if (hours < 10) {
2124
return `0${hours}:${minutes} am`;
2225
}
2326

24-
return `${time}: ${minutes} am`;
27+
return `${time}:${minutes}am`;
2528
}
2629

2730
export { formatAs12HourClock };

0 commit comments

Comments
 (0)