79588647

Date: 2025-04-23 12:47:34
Score: 1
Natty:
Report link

I ended up with generic solution in which I decompose seconds (or whatever I have initially) and then do what I want with result parts.

function sequentialDivision(number, dividers) {
    const divisionResults = [];
    let remains = number;
    for (const divider of dividers) {
        divisionResults.push(Math.floor(remains / divider));
        remains = Math.floor(remains % divider);
    }

    return divisionResults;
}

function secondsToHoursMinutesSeconds(totalSeconds) {
    const [hours, minutes, seconds] = sequentialDivision(totalSeconds, [3600, 60, 1]);
    return {
        hours, 
        minutes,
        seconds,
    };
}

function secondsToHhMmSs(totalSeconds) {
    return sequentialDivision(totalSeconds, [3600, 60, 1])
        .map(s => s.toString().padStart(2,"0"))
        .join(":");
}

Reasons:
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Elgik