Skip to content

Commit b90afe2

Browse files
committed
practice tdd repeat
1 parent 4e8e08c commit b90afe2

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

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

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,36 @@
1-
function repeat(str, count) {
2-
if (count < 0) {
3-
throw new Error("Count must be non-negative");
4-
}
5-
6-
let result = "";
7-
for (let i = 0; i < count; i++) {
8-
result += str;
9-
}
10-
return result;
1+
function repeat() {
2+
if (arguments[1] < 0) throw new Error("Count must be non-negative");
3+
return arguments[0].repeat(arguments[1]);
114
}
5+
//other implementation
6+
// function repeat(str, count) {
7+
// if (count < 0) {
8+
// throw new Error("Count must be non-negative");
9+
// }
1210

13-
module.exports = repeat;
11+
// let result = "";
12+
// for (let i = 0; i < count; i++) {
13+
// result += str;
14+
// }
15+
// return result;
16+
// }
17+
18+
// module.exports = repeat;
19+
20+
// function repeat() {
21+
// const str = arguments[0];
22+
// const count = arguments[1];
23+
24+
// if (count < 0) {
25+
// throw new Error("Count must be non-negative");
26+
// }
27+
28+
// let output = "";
29+
// for (let i = 0; i < count; i++) {
30+
// output += str;
31+
// }
32+
33+
// return output;
34+
// }
35+
36+
// module.exports = repeat;

0 commit comments

Comments
 (0)