Skip to content

Commit 288713b

Browse files
author
umbur
committed
completes repetition
1 parent 98af06f commit 288713b

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

js_draft.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,17 @@
9999
// }
100100
// console.log(addEnding(["clever", "meek", "hurried", "nice"], "ly"));
101101

102-
function getFillings(sandwich) {
103-
return sandwich.filter(() => sandwich.pop());
102+
// function getFillings(sandwich) {
103+
// return sandwich.filter(() => sandwich.pop());
104+
// }
105+
// console.log(getFillings(["bread", "ham", "cheese", "ham", "bread"]));
106+
107+
// function additiveInverse(arr) {
108+
// return arr.map((n) => -n);
109+
// }
110+
// console.log(additiveInverse([5, -7, 8, 3]));
111+
112+
function repetition(txt, n) {
113+
return txt.repeat(n);
104114
}
105-
console.log(getFillings(["bread", "ham", "cheese", "ham", "bread"]));
115+
console.log(repetition("ab", 3));

repetition.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Create a recursive function that takes two parameters and repeats the string n number of times. The first parameter txt is the string to be repeated and the second parameter is the number of times the string is to be repeated.
2+
3+
// String.prototype.repeat() is not allowed
4+
// Examples:
5+
// repetition("ab", 3) ➞ "ababab"
6+
// repetition("kiwi", 1) ➞ "kiwi"
7+
// repetition("cherry", 2) ➞ "cherrycherry"
8+
9+
function repetition(txt, n) {
10+
let word = "";
11+
for (i = 0; i < n; i++) {
12+
word += txt;
13+
}
14+
return word;
15+
}
16+
console.log(repetition("ab", 3));
17+
console.log(repetition("kiwi", 1));
18+
console.log(repetition("cherry", 2));

0 commit comments

Comments
 (0)