Skip to content

Commit 50bce35

Browse files
committed
implemented function
1 parent 2d271a1 commit 50bce35

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
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+
function repeatStr(str, count) {
2+
if (count < 0) {
3+
throw new Error("Error");
4+
}
5+
6+
let repeatedString = "";
7+
for (let i = 0; i < count; i++) {
8+
repeatedString += str;
9+
}
10+
return repeatedString;
511
}
612

713
module.exports = repeatStr;

0 commit comments

Comments
 (0)