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 234e8b6 commit 6a021e3Copy full SHA for 6a021e3
Sprint-3/2-practice-tdd/repeat-str.js
@@ -1,5 +1,19 @@
1
-function repeatStr() {
2
- return "hellohellohello";
+function repeatStr(str, count) {
+ // check if "count" is a negative number if so will throw new error
3
+ if (count < 0) {
4
+ throw new error("Count must be a positive number");
5
+
6
+ //check if the is equal to zero
7
+ if (count === 0){
8
+ return ""; // returns empty string if count is equal to zero
9
+ }
10
+ //check if the count is equals 1.
11
+ if (count === 1) {
12
+ //returns just the string as its not needed to be repeated
13
+ return str;
14
15
+ return str.repeat(count); // if the count is above two it repeat "count" number of times.
16
+}
17
}
18
19
module.exports = repeatStr;
0 commit comments