I know there is a more readable way of writing this:
var string = (
(r.d != 0 ? r.d + (r.d == 1 ? ' day' : ' days') : '' ) +
(r.h != 0 ? r.h + (r.h == 1 ? ' hour' : ' hours') : '' ) +
(r.m != 0 ? r.m + (r.m == 1 ? ' minute' : ' minutes') : '' ) +
(r.s != 0 ? r.s + (r.s == 1 ? ' second' : ' seconds') : '' ));
Try something a bit more readable:
Use as:
You can even go nuts and add this to the
prototype, and end up withr.days.singleOrPlural('day', 'days'), but I don’t think it’s needed here.