Skip to content

Instantly share code, notes, and snippets.

@tomysmile
Last active June 18, 2022 15:13
Show Gist options
  • Save tomysmile/682b5a12214f6cae1f47 to your computer and use it in GitHub Desktop.
Save tomysmile/682b5a12214f6cae1f47 to your computer and use it in GitHub Desktop.
JavaScript: Get Ordinal
function getOrdinal(n) {
   var s=["th","st","nd","rd"],
       v=n%100;
   return n+(s[(v-20)%10]||s[v]||s[0]);
}
@keshavgupta848101
Copy link

function makeItOrdinal(numbers) {
const newArray = [];
for (n of numbers) {
let s = ["th", "st", "nd", "rd"];
let temp = n % 100;
newArray.push(n + (s[(temp - 20) % 10] || s[temp] || s[0]));
}
return newArray;
}
const numbers = [1, 2, 3, 4, 5, 6, 7];

Please explain this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment