View Single Post
Old 10-12-2012, 08:49 PM   PM User | #43
bardonw
New Coder

 
Join Date: Dec 2009
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
bardonw is an unknown quantity at this point
Quote:
Originally Posted by Philip M View Post
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.
bardonw is offline   Reply With Quote