Skip to content

Commit 66056ad

Browse files
committed
Update README.md file
1 parent 20c5949 commit 66056ad

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed
Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,45 @@
1-
# 0006 Repate a String Num times
1+
# 0006 Repate a String Num times ( L-I )
2+
## Problem
23

3-
repeat a given string `str` for `num` of times, and return empty in case the num is zero or negative number.
4+
repeat a given string `str` for `num` of times, and return empty in case the num is zero or negative number, and without using `.repeat()` method.
45

5-
#### Note: you are not allowd to use `.repeat()` method.
6+
## Test Cases
67

7-
## For testing:
8+
- str = "A" and num = 5, the function should return "AAAAA".
9+
- str = "A" and num = 0, the function should return "".
10+
- str = "A" and num = 2, the function should return "AA".
11+
- str = "A" and num = -1, the function should return "".
12+
## Solution
813

9-
- run
10-
```
11-
npm i
12-
```
13-
to install mocha library, then run
14-
```
15-
npm test
16-
```
17-
18-
## Solution:
19-
20-
>- JavaScript.
21-
22-
```
14+
```javascript
2315
const repeatStringNumTimes = (str, num) => {
2416
if (num < 1) {
2517
return "";
2618
}
2719
// here I used recursion technique to solve the problem
2820
return str + repeatStringNumTimes(str, num - 1);
2921
};
22+
23+
console.log(repeatStringNumTimes("abc", 3));
3024
```
3125

32-
[click](https://www.khanacademy.org/computing/computer-science/algorithms/recursive-algorithms/a/recursion) To lern more about recursion method
26+
## How it works
27+
28+
- The function takes two parameters.
29+
- The first is a string, and the second a integer number.
30+
- If the the second parameter is number and positive, it will return the string * number of times.
31+
32+
## References
33+
34+
- [Khan Academy](https://www.khanacademy.org/computing/computer-science/algorithms/recursive-algorithms/a/recursion)
35+
- [FreeCodeCamp](https://www.freecodecamp.org/news/three-ways-to-repeat-a-string-in-javascript-2a9053b93a2d/)
36+
37+
## Problem Added By
38+
- [GitHub](https://github.com/ibr5500)
39+
- [LinkedIn](https://www.linkedin.com/in/ibrahim-ahmat/)
40+
- [Twitter](https://twitter.com/ibr_ahmat)
41+
42+
## Contributing
43+
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
3344

45+
Please make sure to update tests as appropriate.

0 commit comments

Comments
 (0)