Created
November 13, 2020 16:45
-
-
Save kingnebby/e5519dcbc342b1eafc30eb22af8502bd to your computer and use it in GitHub Desktop.
Clean Code Solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function humanReadable(seconds) { | |
let hours = getHours(seconds) | |
let mins = getMins(seconds - (hours * 60 * 60)) | |
let sec = seconds - (mins * 60) - (hours * 60 * 60) | |
return [hours, mins, sec].map(padZerosToTensPlace).join(':') | |
} | |
function getHours(seconds) { | |
return Math.floor((seconds / (60 * 60))) | |
} | |
function getMins(seconds) { | |
return Math.floor(seconds / 60) | |
} | |
function padZerosToTensPlace(value) { | |
return (value / 10 > 1) ? '' + value : `0${value}` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment