Skip to content

Commit 73f8459

Browse files
committed
Implement repeat-str
1 parent db30440 commit 73f8459

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

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

717
module.exports = repeatStr;

0 commit comments

Comments
 (0)