Last active
February 27, 2019 10:39
-
-
Save jakewtaylor/120eed6f0f49c098902c9d29628163c6 to your computer and use it in GitHub Desktop.
This file contains 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
const ordinal = n => { | |
const options = ['th', 'st', 'nd', 'rd']; | |
const v = n % 100; | |
return options[(v - 20) % 10] | |
|| options[v] | |
|| options[0]; | |
}; |
This file contains 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
const ordinal = n => ['st', 'nd', 'rd'][((n + 90) % 100 - 10) % 10 - 1] || 'th'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment