Tell us what’s happening:
I checked the solution and seen the correct way of writing this recursively, but I’m curious why this returns in multiple lines. Is there a way to put everything into one?
Your code so far
function repeatStringNumTimes(str, num) {
if (num <= 0) return []
else if (num === 1) console.log(str)
else console.log(str) + repeatStringNumTimes(str, num - 1)
}
repeatStringNumTimes("abc", 3);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
.
Challenge: Repeat a String Repeat a String
Link to the challenge: