Skip to content

Commit 1515f0b

Browse files
implemented the test cases
1 parent cee43cc commit 1515f0b

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
function formatAs12HourClock(time) {
2-
32
const hours = Number(time.slice(0, 2));
3+
const minutes = time.slice(3, 5);
44

5+
if (hours === 0) {
6+
return `12:${minutes} am`;
7+
}
8+
if (hours === 12) {
9+
return `12:${minutes} pm`;
10+
}
511
if (hours > 12) {
6-
return `${hours - 12}:00 pm`;
12+
return `${String(hours - 12).padStart(2, "0")}:${minutes} pm`;
713
}
814
return `${time} am`;
915
}
1016

11-
export {formatAs12HourClock};
17+
export { formatAs12HourClock };

0 commit comments

Comments
 (0)