Guest User

Untitled

a guest
Nov 15th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. const humanizedSeconds = seconds => [
  2. Math.floor(seconds / 3600),
  3. Math.floor(seconds / 60) % 60,
  4. Math.floor(seconds) % 60
  5. ].map(
  6. (t, i, a) => a.slice(0, i + 1).some(Boolean) ?
  7. String(t).padStart(a.slice(0, i).some(Boolean) ? 2 : 1, '0') :
  8. ''
  9. ).filter(Boolean).join(':');
  10.  
  11. humanizedSeconds(0) // ''
  12. humanizedSeconds(1) // '1'
  13. humanizedSeconds(59) // '59'
  14. humanizedSeconds(60) // '1:00'
  15. humanizedSeconds(61) // '1:01'
  16. humanizedSeconds(3599) // '59:59'
  17. humanizedSeconds(3600) // '1:00:00'
  18. humanizedSeconds(3601) // '1:00:01'
  19. humanizedSeconds(3660) // '1:01:00'
  20. humanizedSeconds(3661) // '1:01:01'
Add Comment
Please, Sign In to add comment