Skip to content

Commit 81f14c5

Browse files
solve excersise repeat-str.js
1 parent d48367c commit 81f14c5

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+
return "Error! negative counts are not valid";
6+
}
7+
let result = "";
8+
let counter = count;
9+
while (counter > 0) {
10+
result += str;
11+
counter--;
12+
}
13+
return result;
514
}

0 commit comments

Comments
 (0)