Skip to content

Commit 3443faf

Browse files
Use negative index in slice for minutes to handle variable-length hours
1 parent ddfce92 commit 3443faf

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎Sprint-3/5-stretch-extend/format-time.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// 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.
44
function formatAs12HourClock(time) {
55
const hours = Number(time.slice(0, 2));
6-
const minutes = time.slice(3);
6+
const minutes = time.slice(-2);
77

88
const period = hours >= 12 ? "pm" : "am";
99
const hours12 = hours % 12 === 0 ? 12 : hours % 12;

0 commit comments

Comments
 (0)