function pluralize (n, s) { return n + " " + (n == 1 ? s : s + "s"); } function toTime (time) { var str = []; if (time > 86400) { str.push( pluralize( Math.floor(time / 86400), "day" ) ); } if (time > 3600) { str.push( pluralize( Math.floor(time / 3600) % 24, "hour" ) ); } if (time > 60) { str.push( pluralize( Math.floor(time / 60) % 60, "minute" ) ); } str.push( pluralize( Math.floor(10 * (time % 60)) / 10, "second" ) ); return str.join(", "); }