Skip to content

Commit 76eabc9

Browse files
committed
Refactor repeatStr function: streamline implementation and maintain non-use of String.prototype.repeat
1 parent 6a5a66c commit 76eabc9

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
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-
function repeatStr(str, count) {
5-
if (count < 0) {
6-
throw new Error("Count must be a non-negative integer");
7-
}
8-
let result = "";
9-
for (let i = 0; i < count; i++) {
10-
result += str;
11-
}
12-
return result;
1+
// Your implementation of this function must *not* call String.prototype.repeat (https://developer...)
2+
// The goal is to re-implement that function, not to use it.
3+
function repeatStr(str, count) {
4+
if (count < 0) {
5+
throw new Error("Count must be a non-negative integer");
136
}
14-
15-
module.exports = repeatStr;
7+
let result = "";
8+
for (let i = 0; i < count; i++) {
9+
result += str;
10+
}
11+
return result;
1612
}
13+
14+
module.exports = repeatStr;

0 commit comments

Comments
 (0)