Skip to content

Commit 7323aba

Browse files
committed
Build a function repeat code
1 parent 76de1ca commit 7323aba

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Sprint-3/2-practice-tdd/repeat.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
function repeat() {
2-
return "hellohellohello";
2+
const str = arguments[0];
3+
const count = arguments[1];
4+
if (count < 0) {
5+
throw new Error("Count must be a non-negative integer");
6+
}
7+
let result = "";
8+
for (let i = 0; i < count; i++) {
9+
result += str;
10+
}
11+
return result;
312
}
413

514
module.exports = repeat;
15+
16+
console.log(repeat("hello", 3));

0 commit comments

Comments
 (0)