Skip to content

Commit ac6fa53

Browse files
Implementing the solution for the function repeatStr
1 parent 6916541 commit ac6fa53

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
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+
6+
if (count === 0) {
7+
return "";
8+
}
9+
10+
let result = "";
11+
12+
for (let i = 0; i < count; i++) {
13+
result += str;
14+
}
15+
16+
return result;
317
}
418

519
module.exports = repeatStr;

0 commit comments

Comments
 (0)