Skip to content

Commit 6df3f4d

Browse files
committed
simplifying time with padStart.
1 parent 373fee6 commit 6df3f4d

1 file changed

Lines changed: 3 additions & 12 deletions

File tree

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,11 @@ function formatAs12HourClock(time) {
1111
}
1212

1313
if (hours > 12) {
14-
const time = hours - 12;
15-
16-
if (time < 10) {
17-
return `0${time}:${minutes} pm`;
18-
}
19-
20-
return `${hours - 12}:${minutes} pm`;
21-
}
22-
23-
if (hours < 10) {
24-
return `0${hours}:${minutes} am`;
14+
const pmHours = hours - 12;
15+
return `${String(pmHours).padStart(2, "0")}:${minutes} pm`;
2516
}
2617

27-
return `${hours}:${minutes} am`;
18+
return `${String(hours).padStart(2, "0")}:${minutes} am`;
2819
}
2920

3021
export { formatAs12HourClock };

0 commit comments

Comments
 (0)