Created
December 15, 2017 09:55
-
-
Save black-black-cat/2cfbf196e4d0c59dd57f01346d527e33 to your computer and use it in GitHub Desktop.
处理英文序号 th, st, nd, rd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getOrdinal(n) { | |
| var s=["th","st","nd","rd"], | |
| v=n%100; | |
| return n+(s[(v-20)%10]||s[v]||s[0]); | |
| } | |
| function ordinal_suffix_of(i) { | |
| var j = i % 10, | |
| k = i % 100; | |
| if (j == 1 && k != 11) { | |
| return i + "st"; | |
| } | |
| if (j == 2 && k != 12) { | |
| return i + "nd"; | |
| } | |
| if (j == 3 && k != 13) { | |
| return i + "rd"; | |
| } | |
| return i + "th"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment