File tree Expand file tree Collapse file tree 1 file changed +7
-9
lines changed
Expand file tree Collapse file tree 1 file changed +7
-9
lines changed Original file line number Diff line number Diff line change 11function repeat ( valueToRepeat , numOfTimes ) {
2+ // Validate valueToRepeat
3+ if ( typeof valueToRepeat !== "string" ) {
4+ return "Invalid input: valueToRepeat should be a string" ;
5+ }
26 // Validate numOfTimes
37 if ( ! Number . isInteger ( numOfTimes ) ) {
4- return "Invalid numOfTimes : numOfTimes should be an integer" ;
8+ return "Invalid input : numOfTimes should be an integer" ;
59 }
10+
611 if ( numOfTimes < 0 ) {
712 return "Negative number invalid" ;
813 }
914 if ( numOfTimes === 0 ) {
1015 return "" ;
1116 }
1217
13- // Convert arrays to empty string
14- if ( Array . isArray ( valueToRepeat ) ) {
15- valueToRepeat = "" ;
16- }
17-
18- // Convert other types to string
19- const strValue = String ( valueToRepeat ) ;
2018
2119 // Repeat the string
2220 let repeatedValue = "" ;
2321 for ( let i = 0 ; i < numOfTimes ; i ++ ) {
24- repeatedValue += strValue ;
22+ repeatedValue += valueToRepeat ;
2523 }
2624
2725 return repeatedValue ;
You can’t perform that action at this time.
0 commit comments