The Recursion challenge i think needs to be revised

Tell us what’s happening:

hi

The explanation on recursion in my opinion in this challenge is not that understandable. I already got the answer I sought after spending much time searching. Even the help video has no video and has an article that doesn’t explain much.

The best video that helped to understand the call stack is this

I hope you will do some changes on the challenge for people not to get lost in it.

Many thanks

Your code so far




function countdown(n) {
// base case
if (n === 1) return [1];

const output = [n]; // [2]
return output.concat(countdown(n - 1)); // [2, 1]
}

countdown(5);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36.

Challenge: Replace Loops using Recursion

Link to the challenge:

Thanks for your enthusiasm for helping improve freeCodeCamp. If you have a specific suggestion on how to improve the content in the lesson, you can go to the freeCodeCamp GitHub and create an issue on the issue tracker.

However, it has been my experience that recursion is a particularly difficult topic to understand, requiring synthesis of many previous ideas. Because of this complexity, I’m not sure that there is a single ‘right’ way to teach recursion that every learner can understand.

Thanks for the directions.

True recursion, as I read, is a tough topic to understand.

But in the mentioned challenge, there is no explanation or example of what is exactly going on. The stack call is not even mentioned. It’s like I am starring at a blue sky trying to find a star.

When I read this line for the first time “However, notice that multiply(arr, n) == multiply(arr, n - 1) * arr[n - 1] .” I was like ha!? Plus the rest of the explanation.

There should be an example with a given array and showing how the functions stacks.

Example:

function multiply(arr, n) {
if (n <= 0) {
return 1;
} else {
return multiply(arr, n - 1) * arr[n - 1];
}
}

var heaven = [1,2,3];
console.log(multiply(heaven,3));
etc

It looks like there is a challenge missing. before this challenge maybe there was a challenge that talks about how functions stack. But even though if that existed still the explanation is not understandable in this challenge.

I am not complaining. I know the course is free and i thank you guys for this too much.

But this challenge needs to be corrected for others to understand exactly whats going on in the problem. From all the challenges that I passed, I realized this one is not explained properly. When I came to this challenge I thought maybe I can write an article to explain this challenge in an understandable way as possible.

Anyway. just wanted to point out this challenge need fixing. maybe i will check the issue tracker thing later.

Thanks :metal:

I had no issue with this line, but I am probably used to that language because of the maths I studied - without knowing about call stack or anything

for example, definition of the factorial function:

f(0) = 1
f(n) = n * f(n-1)

I understand that with no issue, and I have just translated the scheme I have in my mind for those kind of functions, to JavaScript

here the section in Khan Academy:

that, and all the mathematical functions part, actually
it’s a complex subject, it’s really difficult to put it in a way that is fine for everyone

It’s great that the call stack was helpful for you. It confuses some people.

1 Like

Thanks :love_you_gesture: