@@ -18,3 +18,67 @@ test("should append 'st' for numbers ending with 1, except those ending with 11"
1818 expect ( getOrdinalNumber ( 21 ) ) . toEqual ( "21st" ) ;
1919 expect ( getOrdinalNumber ( 131 ) ) . toEqual ( "131st" ) ;
2020} ) ;
21+
22+ // Case 2: Numbers ending with 2 (but not 12)
23+ test ( "should append 'nd' for numbers ending with 2, except those ending with 12" , ( ) => {
24+ expect ( getOrdinalNumber ( 112 ) ) . toEqual ( "112th" ) ;
25+ expect ( getOrdinalNumber ( 32 ) ) . toEqual ( "32nd" ) ;
26+ expect ( getOrdinalNumber ( 332 ) ) . toEqual ( "332nd" ) ;
27+ } ) ;
28+
29+
30+ // Case 3: Numbers ending with 3 (but not 13)
31+ test ( "should append 'rd' for numbers ending with 3, except those ending with 13" , ( ) => {
32+ expect ( getOrdinalNumber ( 113 ) ) . toEqual ( "113th" ) ;
33+ expect ( getOrdinalNumber ( 23 ) ) . toEqual ( "23rd" ) ;
34+ expect ( getOrdinalNumber ( 453 ) ) . toEqual ( "453rd" ) ;
35+ } ) ;
36+
37+
38+ // Case 4: Numbers ending with 4 -9
39+ test ( "should append 'th' for numbers ending with 4" , ( ) => {
40+ expect ( getOrdinalNumber ( 124 ) ) . toEqual ( "124th" ) ;
41+ expect ( getOrdinalNumber ( 235 ) ) . toEqual ( "235th" ) ;
42+ expect ( getOrdinalNumber ( 16 ) ) . toEqual ( "16th" ) ;
43+ expect ( getOrdinalNumber ( 17 ) ) . toEqual ( "17th" ) ;
44+ expect ( getOrdinalNumber ( 18 ) ) . toEqual ( "18th" ) ;
45+ expect ( getOrdinalNumber ( 19 ) ) . toEqual ( "19th" ) ;
46+ } ) ;
47+
48+
49+
50+
51+ // Case 5: Numbers ending with 11, 12, 13
52+ test ( "should append 'th' for numbers ending with 11, 12, 13" , ( ) => {
53+ expect ( getOrdinalNumber ( 11 ) ) . toEqual ( "11th" ) ;
54+ expect ( getOrdinalNumber ( 12 ) ) . toEqual ( "12th" ) ;
55+ expect ( getOrdinalNumber ( 13 ) ) . toEqual ( "13th" ) ;
56+ expect ( getOrdinalNumber ( 111 ) ) . toEqual ( "111th" ) ;
57+ expect ( getOrdinalNumber ( 112 ) ) . toEqual ( "112th" ) ;
58+ expect ( getOrdinalNumber ( 113 ) ) . toEqual ( "113th" ) ;
59+ } ) ;
60+
61+
62+ // Case 6: Numbers ending with 0
63+ test ( "should append 'th' for numbers ending with 0" , ( ) => {
64+ expect ( getOrdinalNumber ( 10 ) ) . toEqual ( "10th" ) ;
65+ expect ( getOrdinalNumber ( 20 ) ) . toEqual ( "20th" ) ;
66+ expect ( getOrdinalNumber ( 30 ) ) . toEqual ( "30th" ) ;
67+ expect ( getOrdinalNumber ( 140 ) ) . toEqual ( "140th" ) ;
68+ } ) ;
69+ function repeatStr ( ) {
70+ let result = "" ;
71+
72+
73+ for ( let i = 0 ; i < num ; i ++ ) {
74+ result += str ;
75+ }
76+
77+
78+ return result ;
79+ }
80+
81+
82+ module . exports = repeatStr ;
83+
84+
0 commit comments