Skip to content

Commit 9c52ea9

Browse files
committed
fixing code based on mentor feedback
1 parent 5ef5dac commit 9c52ea9

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
function repeatStr(str, num) {
2-
let result = "";
32
// 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).
43
// The goal is to re-implement that function, not to use it.
5-
64
if (num < 0) {
75
throw new Error();
86
}
7+
let result = "";
8+
for (let i = 0; i < num; i++) {
9+
result += str;
10+
}
911

10-
return str.repeat(num);
12+
return result;
1113
}
1214

1315
module.exports = repeatStr;

0 commit comments

Comments
 (0)