Skip to content

Commit d9b1f22

Browse files
committed
Repeat String
1 parent 4dff23e commit d9b1f22

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

7_Repeat-String/index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Repeat String
2+
// Write a function that takes in a string and a number, and repeats the string that number of times
3+
4+
const repeatString = (str, num) => {
5+
let repeatedStr = ''
6+
while (num > 0) {
7+
repeatedStr += str
8+
num--
9+
}
10+
return repeatedStr
11+
}
12+
13+
console.log(repeatString('Hello', 4))
14+
console.log(repeatString('Bacon', 3))
15+
console.log(repeatString('hey', 1))
16+
console.log(repeatString('word', 0))
17+
18+
//
19+
//
20+
// or super simple
21+
const easyStrRepeat = (str, num) => {
22+
return str.repeat(num)
23+
}
24+
25+
console.log(easyStrRepeat('Hello', 4))
26+
console.log(easyStrRepeat('Bacon', 3))
27+
console.log(easyStrRepeat('hey', 1))
28+
console.log(easyStrRepeat('word', 0))

0 commit comments

Comments
 (0)