https://www.codewars.com/kata/52685f7382004e774f0001f7
Codewars - Achieve mastery through coding practice and developer mentorship
A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!
www.codewars.com
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 - 99
- MM = minutes, padded to 2 digits, range: 00 - 59
- SS = 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.
코드
function humanReadable (seconds) {
const h = parseInt(seconds / 3600);
const m = parseInt(seconds % 3600 / 60);
const s = (seconds % 60);
return fm(h) + ':' + fm(m) + ':' + fm(s);
}
function fm(num){
return num.toString().padStart(2, '0');
}
'알고리즘 > Codewars' 카테고리의 다른 글
[Codewars] Beginner Series #1 School Paperwork (8 kyu) / JavaScript (0) | 2023.01.17 |
---|---|
[Codewars] Invert values (8 kyu) / JavaScript (0) | 2023.01.16 |
[Codewars] Find the divisors! (7 kyu) / JavaScript (0) | 2023.01.13 |
[Codewars] Opposites Attract (8 kyu) / JavaScript (0) | 2023.01.12 |
[Codewars] Sort the odd (6 kyu) / JavaScript (0) | 2023.01.11 |
댓글