Skip to content

Commit 11a1b98

Browse files
committed
feat: enhance repeatStr function to handle negative counts and improve string repetition logic
1 parent b498ab0 commit 11a1b98

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
function repeatStr() {
2-
return "hellohellohello";
1+
function repeatStr(str, count) {
2+
if (count < 0) {
3+
throw new Error("count cannot be negative");
4+
}
5+
if (count === 1) return str;
6+
7+
let result = "";
8+
for (let i = 0; i < count; i++) {
9+
result = result + str;
10+
}
11+
return result;
312
}
413

514
module.exports = repeatStr;
15+

0 commit comments

Comments
 (0)