We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0f8bc3b commit a36b127Copy full SHA for a36b127
1 file changed
Sprint-3/2-practice-tdd/repeat-str.js
@@ -1,5 +1,22 @@
1
-function repeatStr() {
2
- return "hellohellohello";
+function repeatStr(str, count) {
+ if (count < 0) {
3
+ throw new Error("Count cannot be negative");
4
+ }
5
+
6
+ if (count === 0) {
7
+ return "";
8
9
10
+ if (count === 1) {
11
+ return str;
12
13
14
+ let result = "";
15
+ for (let i = 0; i < count; i++) {
16
+ result += str;
17
18
19
+ return result;
20
}
21
-module.exports = repeatStr;
22
+module.exports = repeatStr;
0 commit comments