Human Readable Time
4088 단어 CodewarsJavaScriptCodewars
Description:
Write a function, which takes a non-negative integer (seconds) as input and returns the time in a human-readable format (HH:MM:SS
)
HH
= hours, padded to 2 digits, range: 00 - 99MM
= minutes, padded to 2 digits, range: 00 - 59SS
= seconds, padded to 2 digits, range: 00 - 59
The maximum time never exceeds 359999 (99:59:59
)
You can find some examples in the test fixtures.
My solution:
function humanReadable (seconds) {
// get number
const hour = parseInt(seconds / 3600);
const minute = parseInt(seconds % 3600 / 60);
const second = parseInt(seconds % 3600 % 60);
// modify number into given form
function modify(number) {
let stringNumber = String(number);
if(stringNumber.length == 1) {
stringNumber = '0'+stringNumber;
}
return stringNumber;
}
return modify(hour)+':'+modify(minute)+':'+modify(second);
}
Best solutions:
별반 다르지 않다.
Author And Source
이 문제에 관하여(Human Readable Time), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@gtfo/Human-Readable-Time저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)