function howManyTimes(num, str) {
if (!str) str = '';
if (num > 0) {
return howManyTimes(num - 1, str + 'a');
} else {
return `Ed${str}bit`;
}
}
console.log(howManyTimes(8));
One issue is that your recursion is always appending the result of the method to an a. Rather than doing that, pass along the aggregated string to then be used once you reach the end.
I'm someone who's been through a handful of basic tutorials. I know what can be done, but every single time I try to actually code my own stuff, I end up Googling basic things.
I tried to follow along with big projects, but so much started to go over my head. I knew I needed a simpler way to learn if I wanted to make more progress.
Edabit is a Godsend for people in my position because it allows me to practice a lot of different types of problems with a high frequency. If you're struggling to go from "super beginner" to "beginner" I highly recommend it!
Link for those interested.
PS. I'm no way affiliated with them
javascript - Recursion challenge - Edabit - Stack Overflow
Coding problem solution not working
Where to get good practice for javascript like edabit.com?
On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge.
If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options:
-
Limiting your involvement with Reddit, or
-
Temporarily refraining from using Reddit
-
Cancelling your subscription of Reddit Premium
as a way to voice your protest.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
More on reddit.comjavascript - My code passes all my tests but some how edabit is not approving it - Stack Overflow
function howManyTimes(num, str) {
if (!str) str = '';
if (num > 0) {
return howManyTimes(num - 1, str + 'a');
} else {
return `Ed${str}bit`;
}
}
console.log(howManyTimes(8));
One issue is that your recursion is always appending the result of the method to an a. Rather than doing that, pass along the aggregated string to then be used once you reach the end.
You can always separate out the part that can use straightforward recursion from a shell that calls that part and does something with the result. For instance,
const nAs = (n) =>
n == 0 ? '' : nAs (n - 1) + 'a'
const howManyTimes = (n) =>
`Ed${nAs (n)}bit`
console .log (howManyTimes (0))
console .log (howManyTimes (1))
console .log (howManyTimes (10))
Of course I would only write it this way in a recursion challenge. For this example, there are more straightforward ways to write this, including const howManyTimes = (n) => `Ed${'a'.repeat(n)}bit`
Anyone have good alternatives to https://edabit.com/pro? I don't really want to bite the bullet for a year. Wish they had a $10 per month option you could cancel anytime.
On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge.
If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options:
-
Limiting your involvement with Reddit, or
-
Temporarily refraining from using Reddit
-
Cancelling your subscription of Reddit Premium
as a way to voice your protest.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
I looked at it briefly. I'll take another look and try it out more, thanks.