0
Given seconds like 11728, write the smallest javascript function that returns a string like 3hrs. 15min. 28sec.
signature textTime([int] t,[bool] z,[bool] m)
t
is the time like 11728 and you can assume int
z
is optional and true means drop zero times, so 3hrs. 0min. 28sec.
becomes 3hrs. 28sec.
m
is optional and true means show only up to minutes, so 3hrs. 16min. 48sec.
is 3hrs. 16min.
For 1 hour, 1hrs.
is fine (vs 1hr.
)
Example:
textTime(11728) returns "3hrs. 0min. 28sec."
textTime(11728,true) returns "3hrs. 28sec."
textTime(11728,true,true) returns "3hrs."
Regex is fine, speed is inconsequential.
Shortest code wins.
4Your function parameters don't make any sense. – Shmiddty – 2013-09-12T18:14:47.263
1What about days, weeks, months and years? Examples don't make a specification. – Johannes Kuhn – 2013-09-13T07:43:03.093
this is not "date time", but a measure of hours and minutes and seconds. 1 day is not exactly 24hours and 0 secs, so a lot of things are measured in hours, which is the highest level measure of "real" time – AwokeKnowing – 2013-09-13T19:10:53.700
I apologize for using [brackets] to state the var type, which made it look like an array. maybe [int] t would have been better. – AwokeKnowing – 2013-09-13T19:20:37.567
http://jsfiddle.net/CA6GM/2/ "Javascript 120" – cocco – 2014-05-27T12:22:27.000