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 1a5ddc6 commit d4aba95Copy full SHA for d4aba95
Sprint-3/2-practice-tdd/repeat-str.js
@@ -1,5 +1,25 @@
1
-function repeatStr() {
2
- return "hellohellohello";
+function repeatStr(stringToRepeat, numberOfRepetitions) {
+ // Handle count of 0
3
+ if (numberOfRepetitions === 0) {
4
+ return "";
5
+ }
6
+
7
+ // Handle count of 1
8
+ if (numberOfRepetitions === 1) {
9
+ return stringToRepeat;
10
11
12
+ // Handle multiple repetitions (> than 1)
13
+ if (numberOfRepetitions > 1) {
14
+ let finalString = "";
15
16
+ // loop for repeating the string and concatenating it to the final string
17
+ for (let repetition = 0; repetition < numberOfRepetitions; repetition++) {
18
+ finalString = finalString + stringToRepeat;
19
20
21
+ return finalString;
22
23
}
24
25
module.exports = repeatStr;
0 commit comments