Skip to content

Commit 1b5fe5e

Browse files
committed
Simplify displayHour and use slice(-2) for minutes
1 parent f016ea8 commit 1b5fe5e

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22

33
function formatAs12HourClock(time) {
44
const hours = Number(time.slice(0, 2));
5-
const minutes = time.slice(3, 5);
5+
const minutes = time.slice(-2);
66

77
const period = hours >= 12 ? "pm" : "am";
88

9-
let displayHour = hours % 12;
10-
if (displayHour === 0) {
11-
displayHour = 12;
12-
}
9+
const displayHour = hours % 12 || 12;
1310

1411
return `${displayHour}:${minutes} ${period}`;
1512
}

0 commit comments

Comments
 (0)