Skip to content

Commit ec5846f

Browse files
committed
Implement repeatStr without repeat method
1 parent 3420818 commit ec5846f

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
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).
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).
33
// The goal is to re-implement that function, not to use it.
4-
return "hellohellohello";
4+
// return "hellohellohello";
5+
// }
6+
7+
// module.exports = repeatStr;
8+
function repeatStr(string, times) {
9+
let result = "";
10+
11+
for (let i = 0; i < times; i++) {
12+
result += string;
13+
}
14+
15+
return result;
516
}
617

7-
module.exports = repeatStr;
18+
module.exports = repeatStr;

0 commit comments

Comments
 (0)