Skip to content

Commit e3f5cd6

Browse files
committed
Write function for 2-practice-tdd/repeat.str.js
1 parent 67d8660 commit e3f5cd6

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
function repeatStr() {
1+
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("Number must be 0 or greater");
7+
}
8+
9+
let repeatedStr = "";
10+
for (let i = 0; i < count; i++) {
11+
repeatedStr += str;
12+
}
13+
return repeatedStr;
514
}
615

716
module.exports = repeatStr;

0 commit comments

Comments
 (0)