View Single Post
Old 10-11-2012, 08:03 AM   PM User | #42
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by AndrewGSW View Post
Code:
XX = "thstndrd".substr((D % 10) * (D < 11 || D > 13) * 2, 2) || "th";
.. works with non-date numbers.
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!
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 10-11-2012 at 08:07 AM..
Philip M is offline   Reply With Quote