Skip to content

Commit afa99b8

Browse files
committed
Implement repeatStr function
1 parent ea11468 commit afa99b8

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

‎practice-tdd/repeat-str.js‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
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+
if (count < 0) {
5+
throw new Error("Error - invalid count number");
6+
}
7+
8+
let repeatedStr = "";
9+
for (let i = count; i > 0; i--) {
10+
repeatedStr += str;
11+
}
12+
13+
return repeatedStr;
514
}

0 commit comments

Comments
 (0)