Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const humanizedSeconds = seconds => [
- Math.floor(seconds / 3600),
- Math.floor(seconds / 60) % 60,
- Math.floor(seconds) % 60
- ].map(
- (t, i, a) => a.slice(0, i + 1).some(Boolean) ?
- String(t).padStart(a.slice(0, i).some(Boolean) ? 2 : 1, '0') :
- ''
- ).filter(Boolean).join(':');
- humanizedSeconds(0) // ''
- humanizedSeconds(1) // '1'
- humanizedSeconds(59) // '59'
- humanizedSeconds(60) // '1:00'
- humanizedSeconds(61) // '1:01'
- humanizedSeconds(3599) // '59:59'
- humanizedSeconds(3600) // '1:00:00'
- humanizedSeconds(3601) // '1:00:01'
- humanizedSeconds(3660) // '1:01:00'
- humanizedSeconds(3661) // '1:01:01'
Add Comment
Please, Sign In to add comment