Quote:
Originally Posted by Philip M
No it doesn't!
Code:
var D = 112;
var XX = "thstndrd".substr((D % 10) * (D < 11 || D > 13) * 2, 2) || "th";
alert (XX); // nd!!!
Code:
var D = 112;
var XX = "thstndrd".substr((D % 10) * !(D % 14 > 9) * 2, 2) || "th";
alert (XX); // nd!!!
See Post # 31 - that does work!
|
I think that is a good version and I definitely spent some time looking at how to make it work a bit differently. The only problem I have is the fact that in that version, the array of ordinals is created every time the function is run. That means that the function will run slower if run on many thousands of numbers. Still, for most cases, that function will do. I just know that people like John Resig or Douglas Crockford would not like me endorsing that as the best solution.