File tree Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -4,15 +4,19 @@ function repeat(str, count) {
44 if ( count === 0 ) {
55 return newStr ;
66 } else if ( count === 1 ) {
7- return ( newStr += str ) ;
7+ return str ;
88 } else if ( count > 1 ) {
99 for ( let i = 0 ; i < count ; i ++ ) {
1010 newStr += str ;
1111 }
1212 return newStr ;
1313 } else {
14- return "Error invalid count used, please use integers from 0 upwards." ;
14+ throw new Error (
15+ "Error invalid count used, please use integers from 0 upwards."
16+ ) ;
17+ //return "Error invalid count used, please use integers from 0 upwards.";
1518 }
19+ return true ;
1620}
1721
1822module . exports = repeat ;
Original file line number Diff line number Diff line change @@ -45,8 +45,10 @@ test("should return an empty string", () => {
4545test ( "should throw an error for invalid count" , ( ) => {
4646 const str = "hello" ;
4747 const count = - 4 ;
48- const repeatedStr = repeat ( str , count ) ;
49- expect ( repeatedStr ) . toEqual (
48+ function repeatedStr ( ) {
49+ repeat ( str , count ) ;
50+ }
51+ expect ( repeatedStr ) . toThrow (
5052 "Error invalid count used, please use integers from 0 upwards."
5153 ) ;
5254} ) ;
You can’t perform that action at this time.
0 commit comments