File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed
Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change 11function getOrdinalNumber ( num ) {
2- let remainder1 = num % 10 ;
3- let remainder2 = num % 100 ;
4- if ( remainder1 === 1 && remainder2 !== 11 ) {
2+ let lastDigit = num % 10 ;
3+ let lastTwoDigits = num % 100 ;
4+ if ( lastDigit === 1 && lastTwoDigits !== 11 ) {
55 // we also can use if (num[-1]===1 && num.slice(-2)!==11)
66 return num + "st" ;
7- } else if ( remainder1 === 2 && remainder2 !== 12 ) {
7+ } else if ( lastDigit === 2 && lastTwoDigits !== 12 ) {
88 // we also can use if (num[-1]===2 && num.slice(-2)!==12)
99 return num + "nd" ;
10- } else if ( remainder1 === 3 && remainder2 !== 13 ) {
10+ } else if ( lastDigit === 3 && lastTwoDigits !== 13 ) {
1111 // we also can use if (num[-1]===3 && num.slice(-2)!==13)
1212 return num + "rd" ;
1313 } else {
You can’t perform that action at this time.
0 commit comments