Skip to content

Instantly share code, notes, and snippets.

@farukcan
Last active October 5, 2022 18:04
Show Gist options
  • Save farukcan/10f0b8e75d7d126a4f732e3e1d529873 to your computer and use it in GitHub Desktop.
Save farukcan/10f0b8e75d7d126a4f732e3e1d529873 to your computer and use it in GitHub Desktop.
JS getOrdinal(n)
// check : https://byjus.com/maths/ordinal-numbers/
function getOrdinal(n) {
let ord = 'th';
if (n % 10 == 1 && n % 100 != 11)
{
ord = 'st';
}
else if (n % 10 == 2 && n % 100 != 12)
{
ord = 'nd';
}
else if (n % 10 == 3 && n % 100 != 13)
{
ord = 'rd';
}
return ord;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment