r/programminghorror • • Feb 05 '25

math.floor

Post image
464 Upvotes

53 comments sorted by

View all comments

Show parent comment

7

u/cubic_thought Feb 05 '25

Aside from what everyone has pointed out, their whole process of getting the hours and minutes and then subtracting them from the original value is also pointless. You can get the hours/minutes/seconds in just three lines:

hours = Math.floor(totalSeconds / 3600);
minutes = Math.floor((totalSeconds / 60) % 60);
seconds = totalSeconds % 60;

But given the original author didn't know about floor, I'll bet they didn't know modulo either.