I found myself in need of a function to get the ordinal suffix for any number. Naturally, I googled and found some examples out there but they all seemed to have many lines of code and I felt an uncontrollable urge to see if I could condense it down to one line. I jumped on over to trycf.com and fiddled around for a bit and I came up with this:
As a side note: While I was fiddling around with this completely unnecessary effort (that was likely fueled by my self diagnosed OCD), I did notice an interesting difference between Adobe CF and Lucee that I had not noticed before. It appears that in Lucee you can immediately use a member function when an array is written using implicit notation, but in Adobe CF you have to define the variable separately before you can use the member functions. For example in Lucee I was able to do this (which threw an error in Adobe CF):
That code gave me the warm fuzzies, because it was 14 characters shorter than what I ended up needing to get it to work on one line with Adobe CF. I also just really like having the option to avoid creating variables I don't need. Here is a simplified example of what I am talking about:
Strangely though in ACF you CAN immediately use the member function on a string:
It turns out that there is a bug tracker for this issue in Adobe CF so please head on over and vote for them to fix it:
There are no comments for this entry.
[Add Comment]