This question already has an answer here:

Description :

Given an input (a string , array , integer) , Your job is to append one of the following to it.

st , nd , rd , th .

Examples :

1 ---> 1st 2 ---> 2nd 3 ---> 3rd 4 ---> 4th 11 ---> 11th 12 ---> 12th 13 ---> 13th 14 ---> 14th and so on and so forth

This is code golf so shortest code will win in each language.

Good luck and have fun


marked as duplicate by LyricLy, caird coinheringaahing, user202729, ovs code-golf Apr 14 '18 at 10:07

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • \$\begingroup\$ a string , integer or an array (choose what you like) , all will be integers or can be converted to integers. \$\endgroup\$ – Muhammad Salman Apr 14 '18 at 9:59
  • \$\begingroup\$ You probably should include all special cases such as 11th, 12th and 13th (vs 21st, 22nd, 23rd). \$\endgroup\$ – Arnauld Apr 14 '18 at 10:00
  • \$\begingroup\$ ok. Will do. Thanks \$\endgroup\$ – Muhammad Salman Apr 14 '18 at 10:01
  • 2
    \$\begingroup\$ You may want to turn this into a decision-problem instead: given a string, return a truthy value if it's a valid ordinal number or a falsy value otherwise (e.g. "21st" is true, "12nd" is false). I think that would be quite different from the other challenge. But please wait for feedback from other users before doing so. (Also, it might be a dupe as well... I didn't check.) \$\endgroup\$ – Arnauld Apr 14 '18 at 10:14
  • 1
    \$\begingroup\$ Hi : thank you @Arnauld , I posted this question in the sandbox \$\endgroup\$ – Muhammad Salman Apr 14 '18 at 10:34

Browse other questions tagged or ask your own question.