Last active
          October 5, 2022 18:04 
        
      - 
      
- 
        Save farukcan/10f0b8e75d7d126a4f732e3e1d529873 to your computer and use it in GitHub Desktop. 
    JS getOrdinal(n)
  
        
  
    
      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
    
  
  
    
  | // 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