Skip to content

Commit 7d01f24

Browse files
committed
Fix repeatStr implementation and tests
1 parent 3dd0121 commit 7d01f24

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

‎practice-tdd/repeat-str.js‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1-
export function repeatStr() {
1+
export function repeatStr(str, count) {
22
// Your implementation of this function must *not* call String.prototype.repeat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat).
33
// The goal is to re-implement that function, not to use it.
4-
return "hellohellohello";
4+
5+
if (count < 0) {
6+
throw new Error("count must be non-negative");
7+
}
8+
9+
let result = "";
10+
11+
for (let i = 0; i < count; i++) {
12+
result += str;
13+
}
14+
15+
return result;
516
}

0 commit comments

Comments
 (0)