Skip to content

Commit 44661d3

Browse files
committed
feat: complete repeatStr function
1 parent ecbd8d9 commit 44661d3

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎practice-tdd/repeat-str.js‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
export function repeatStr() {
2-
// 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).
3-
// The goal is to re-implement that function, not to use it.
4-
return "hellohellohello";
1+
export function repeatStr(str, count) {
2+
if (count < 0) {
3+
throw new Error("Count cannot be negative");
4+
}
5+
let result = "";
6+
7+
for (let i = 0; i < count; i++) {
8+
result = result + str;
9+
}
10+
return result;
511
}

0 commit comments

Comments
 (0)