Skip to content

Commit f30a568

Browse files
repeat-str.js remove redundant implementation block: if (count===1)
1 parent ef1e336 commit f30a568

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

‎practice-tdd/repeat-str.js‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@ export function repeatStr(str, count) {
55
if (count === 0) {
66
return "";
77
}
8-
if (count === 1) {
9-
return str;
10-
}
8+
9+
1110
// 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).
1211
// The goal is to re-implement that function, not to use it.
1312
let result = "";
14-
for (let i = 0; i < count; i++) {
15-
result += str;
13+
for (let i = 0; i < count; i++) { // i++ is i=i+1, i+=1, i=i+1, all are valid
14+
result = result + str; //result += str; is also valid
1615
}
1716
return result;
1817

19-
return ("hellohellohello")
18+
2019
}
2120

2221
//let result = ""

0 commit comments

Comments
 (0)