File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed
Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change 11function getOrdinalNumber ( num ) {
22 // Check if input is a number
3- if ( typeof num !== "number" || isNaN ( num ) ) {
3+ if ( typeof num !== "number" || isNaN ( num ) ) || ! Number . isInteger ( num ) || ! Number . isFinite ( num ) ) {
44 throw new Error ( "Input must be a valid number" ) ;
55 }
66
7- const j = num % 10 ; // checks what last number is
8- const k = num % 100 ; // checks what last two numbers are, needed to check for 11
7+ const lastnum = num % 10 ; // checks what last number is
8+ const last2num = % 100 ; // checks what last two numbers are, needed to check for 11
99
10- if ( k === 11 || k === 12 || k === 13 ) {
10+ if ( last2num === 11 || last2num === 12 || last2num === 13 ) {
1111 return num + "th" ;
1212 }
13- if ( j === 1 ) return num + "st" ;
14- if ( j === 2 ) return num + "nd" ;
15- if ( j === 3 ) return num + "rd" ;
13+ if ( lastnum === 1 ) return num + "st" ;
14+ if ( lastnum === 2 ) return num + "nd" ;
15+ if ( lastnum === 3 ) return num + "rd" ;
1616
1717 return num + "th" ;
1818}
You can’t perform that action at this time.
0 commit comments