File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed
Expand file tree Collapse file tree 2 files changed +34
-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+ }
5+ if ( num === 2 ) {
6+ return "2nd" ;
7+ }
8+ if ( num === 3 ) {
9+ return "3rd" ;
10+ }
11+ return num + "th" ;
312}
413
514module . exports = getOrdinalNumber ;
Original file line number Diff line number Diff line change @@ -11,3 +11,27 @@ const getOrdinalNumber = require("./get-ordinal-number");
1111test ( "should return '1st' for 1" , ( ) => {
1212 expect ( getOrdinalNumber ( 1 ) ) . toEqual ( "1st" ) ;
1313} ) ;
14+
15+ // Case 2: Identify the ordinal number for 2
16+ // When the number is 2,
17+ // Then the function should return "2nd"
18+
19+ test ( "should return '2nd' for 2" , ( ) => {
20+ expect ( getOrdinalNumber ( 2 ) ) . toEqual ( "2nd" ) ;
21+ } ) ;
22+
23+ // Case 3: Identify the ordinal number for 3
24+ // When the number is 3,
25+ // Then the function should return "3rd"
26+
27+ test ( "should return '3rd' for 3" , ( ) => {
28+ expect ( getOrdinalNumber ( 3 ) ) . toEqual ( "3rd" ) ;
29+ } ) ;
30+
31+ // Case 4: Identify the ordinal number for other numbers
32+ // When the number is 11,
33+ // Then the function should return "11th"
34+
35+ test ( "should return '11th' for 11" , ( ) => {
36+ expect ( getOrdinalNumber ( 11 ) ) . toEqual ( "11th" ) ;
37+ } ) ;
You can’t perform that action at this time.
0 commit comments