Skip to content

Instantly share code, notes, and snippets.

@black-black-cat
Created December 15, 2017 09:55
Show Gist options
  • Save black-black-cat/2cfbf196e4d0c59dd57f01346d527e33 to your computer and use it in GitHub Desktop.
Save black-black-cat/2cfbf196e4d0c59dd57f01346d527e33 to your computer and use it in GitHub Desktop.
处理英文序号 th, st, nd, rd
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