I had this test:
Implement an function toReadableString(int) that takes an integer that represents number of seconds
from 00:00:00 and returns a printable string format with AM / PM notation.
For ex.
01:00:00 = 3600
07:00:00 = 25200
toReadableString(3600) should return "1:00AM"
toReadableString(25200) should return "7:00AM"
And my solution is:
function padZero(string){
return ("00" + string).slice(-2);
}
function toReadableString(time) {
var hrs = ~~(time / 3600 % 24),
mins = ~~((time % 3600) / 60),
timeType = (hrs>11?"PM":"AM");
return hrs + ":" + padZero(mins) + timeType;
}
But it fails most of test cases. The test cases are hidden, so I don't know why i failed the test. I have tried most of the test cases I could think of. Any ideas what's wrong with my solution?