File tree Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -2,11 +2,11 @@ function repeat(str, count) {
22 if ( typeof str !== "string" && typeof str !== "number" ) {
33 throw new Error ( "Input should be a string" ) ;
44 }
5- if ( Number ( count ) < 0 ) {
6- throw new Error ( "Count should be a positive number" ) ;
5+ if ( Number ( count ) < 0 && Number . isInteger ( Number ( count ) ) ) {
6+ throw new Error ( "Count should be a positive integer number" ) ;
77 }
88 if ( typeof count !== "number" && typeof count !== "string" ) {
9- throw new Error ( "Count should be a number" ) ;
9+ throw new Error ( "Count should be a positive integer number" ) ;
1010 }
1111 return String ( str ) . repeat ( Number ( count ) ) ;
1212}
Original file line number Diff line number Diff line change @@ -45,7 +45,9 @@ test("should return an empty string when count is 0", () => {
4545test ( "should throw an error when count is negative" , ( ) => {
4646 const str = "hello" ;
4747 const count = - 2 ;
48- expect ( ( ) => repeat ( str , count ) ) . toThrow ( "Count should be a positive number" ) ;
48+ expect ( ( ) => repeat ( str , count ) ) . toThrow (
49+ "Count should be a positive integer number"
50+ ) ;
4951} ) ;
5052
5153// case: str is not a string:
@@ -106,5 +108,7 @@ test("should throw an error when str is invalid type", () => {
106108test ( "should throw an error when count is an array" , ( ) => {
107109 const str = "hello" ;
108110 const count = [ 2 ] ;
109- expect ( ( ) => repeat ( str , count ) ) . toThrow ( "Count should be a number" ) ;
111+ expect ( ( ) => repeat ( str , count ) ) . toThrow (
112+ "Count should be a positive integer number"
113+ ) ;
110114} ) ;
You can’t perform that action at this time.
0 commit comments