Last active
February 11, 2024 20:35
-
-
Save dutchcelt/2cde21075520f9d042f9079a8e22190e to your computer and use it in GitHub Desktop.
Convert an index value to an ordinal value
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
// Source: https://stackoverflow.com/questions/13627308/add-st-nd-rd-and-th-ordinal-suffix-to-a-number | |
const ordinalConverter = (i) => { | |
const ordinal = ["st","nd","rd"][((i+90)%100-10)%10-1]||"th"; | |
return `${i}${ordinal}`; | |
}; | |
export ordinalConverter; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment