File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed
Sprint-3/3-mandatory-practice/implement Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change 1- function repeat ( ) {
2- return "hellohellohello" ;
1+ // function repeat() {
2+ // return "hellohellohello";
3+ // }
4+ // The function always returns "hellohellohello" regardless of any input.
5+ // There are no parameters, so it’s not flexible or reusable.
6+ function repeat ( str , count ) {
7+ if ( ! Number . isInteger ( count ) || count < 0 ) {
8+ return "Error: Count must be a non-negative integer" ;
9+ }
10+ return str . repeat ( count ) ;
311}
412
5- module . exports = repeat ;
13+ module . exports = repeat ;
14+ // Example usage:
15+ // console.log(repeat("hello", 3)); // Expected: "hellohellohello"
16+ // console.log(repeat("at", 5)); // Expected: "atatatatat"
17+ // console.log(repeat("test0", 0)); // Expected: ""
18+ // console.log(repeat("", 5)); // Expected: ""
19+ // console.log(repeat("WE", 1)); // Expected: "hi"
You can’t perform that action at this time.
0 commit comments