File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 11function getOrdinalNumber ( num ) {
2- return "1st" ;
2+ if ( num === 1 ) {
3+ return "1st" ;
4+ } else if ( num === 2 ) {
5+ return "2nd" ;
6+ } else if ( num === 3 ) {
7+ console . log ( num ) ;
8+ return "3rd" ;
9+ } else if ( num > 3 || num < 21 ) {
10+ return `${ num } th` ;
11+ }
312}
413
514module . exports = getOrdinalNumber ;
Original file line number Diff line number Diff line change @@ -11,3 +11,15 @@ const getOrdinalNumber = require("./get-ordinal-number");
1111test ( "should return '1st' for 1" , ( ) => {
1212 expect ( getOrdinalNumber ( 1 ) ) . toEqual ( "1st" ) ;
1313} ) ;
14+
15+ test ( "should return '2nd' for 2" , ( ) => {
16+ expect ( getOrdinalNumber ( 2 ) ) . toEqual ( "2nd" ) ;
17+ } ) ;
18+
19+ test ( "should return '3rd' for 3" , ( ) => {
20+ expect ( getOrdinalNumber ( 3 ) ) . toEqual ( "3rd" ) ;
21+ } ) ;
22+
23+ test ( "should return any number between 4 and 20 with a suffix of 'th' at end of number" , ( ) => {
24+ expect ( getOrdinalNumber ( 10 ) ) . toEqual ( "10th" ) ;
25+ } ) ;
You can’t perform that action at this time.
0 commit comments