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 3c69efb commit 7661229Copy full SHA for 7661229
Sprint-3/2-practice-tdd/repeat-str.js
@@ -1,5 +1,21 @@
1
-function repeatStr() {
2
- return "hellohellohello";
+function repeatStr(str, count) {
+ if (count === 0) {
3
+ return "";
4
+ } else if (count === 1) {
5
+ return str;
6
+ } else if (count > 1) {
7
+ return str.repeat(count);
8
+ } else {
9
+ throw new Error("Count cannot be a negative number");
10
+ }
11
}
12
+// I can make the 3 valid cases in 1 case with the repeat method as folows:
13
+// function repeatStr(str, count) {
14
+// if (count >= 0) {
15
+// return str.repeat(count);
16
+// } else {
17
+// throw new Error("Count cannot be a negative number");
18
+// }
19
20
21
module.exports = repeatStr;
0 commit comments