Skip to content

Commit 9b9d6fa

Browse files
committed
Update: fix repeat function to accept parameters and handle non-negative integer counts
1 parent e255a25 commit 9b9d6fa

File tree

1 file changed

+17
-3
lines changed
  • Sprint-3/3-mandatory-practice/implement

1 file changed

+17
-3
lines changed
Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
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"

0 commit comments

Comments
 (0)