Skip to content

Commit a1f992a

Browse files
refactor: use negative slice for minutes as suggested by reviewer
1 parent 92453f8 commit a1f992a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Sprint-2/5-stretch-extend/format-time.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44

55
function formatAs12HourClock(time) {
66
const hours = Number(time.slice(0, 2));
7-
const minutes = time.slice(3, 5);
7+
const minutes = time.slice(-2);
8+
9+
// Basic validation (fix bug: invalid hour values)
10+
if (hours < 0 || hours > 23) {
11+
return "Invalid time";
12+
}
813

914
// If midnight (00), convert to 12 am
1015
if (hours === 0) {
@@ -37,4 +42,4 @@ const targetOutput2 = "11:00 pm";
3742
console.assert(
3843
currentOutput2 === targetOutput2,
3944
`current output: ${currentOutput2}, target output: ${targetOutput2}`
40-
);
45+
);

0 commit comments

Comments
 (0)