Add st, nd, rd and th (ordinal) suffix to a number
Need a function to dynamically append the correct English ordinal suffix (st
, nd
, rd
, or th
) to a number? Below lies your treasure:
My friend, this function maps last digits to the ordinal suffixes, cunningly handling exceptions. Copy and use addOrdinal
and enjoy your abstract celebration of numbers.
Advanced usage and edge cases
Delve deeper into the addOrdinal
function and discover more treasures hidden beneath its surface!
Considering negative numbers
Negative, or antisocial, numbers deserve their place at the ordinal party too:
Modern "cool kids" syntax
Adding moment.js to the mix
Use moment.js
if your code needs a special language touch.
Diving deeper with special cases
Special cases always suit up and shine:
Locale-specific suffixes
Extension to support multiple languages is possible, remember, coding is universal!
Prioritizing performance
Code performance remains crucial for memory usage and CPU time efficiency.
Testing large numbers
Pushing the computational limits by checking the function with large numbers can be revealing!
Was this article helpful?