@Sboonny sorry I mixed up my array names. I’m again trying to make startNum and endNum reach the base case. I thought if I made startNum bigger and endNum smaller each time recursion happened that would work. But it doesn’t.
I tried giving it two arguments but I still don’t know what arguments I need to make it work.
is startNum ever going to be bigger?
…isn’t that the point of the recursion? Making startNum bigger to reach the base case of the else? Otherwise I don’t know how recursion works at all.
Hi, I’m afraid I really struggle to focus on videos and they really don’t work for me to explain coding. I need to either be reading something, or doing it to learn.
Okay I actually don’t understand the previous lesson. I solved it but it makes zero sense why it works. How does n go from -1 to a number over 1 by putting n which is -1 to the front of the array. How does adding two -1 make a positive number?
Recursion seems an over complex solution to simple problems. I really don’t know why it’s better than a for loop when it’s so unrelentingly confusing and hard to implement.
You are correct, you would never use recursion to solve this type of problem in the real world. The lessons here are just trying to introduce you to the concept with very simple examples. There are some problems in which recursion does actually make the solution much easier though. But you probably won’t run into those doing general front end web development.
But if you can understand these simple recursions then you will have a better understanding of how functions work in general and also how recursion works.
I don’t really understand the arguments for your recursive function call.
Every recursive function has the same basic structure
function myRecursiveFunction(arguments) {
if (baseCase) {
return someSimpleValue;
} else {
const intermediateResult = myRecursiveFunction(modifiedArguments);
return modifiedIntermediateValue;
}
}
The base case is the absolute simplest version of the problem. In this challenge, the absolute simplest version of the problem would be a range with no numbers in it.
The recursive case is based upon a simpler version of the problem. Making an array with all values from 7 to 42 is very easy is someone hands you an array with all values from 7 to 41, and you have a function that can make an array with all values from 7 to 41.
There are some problems where recursion is the easiest way to express the logic. This isn’t one of them. This is more of a toy problem to practice the idea of recursion. But it’s hard because 1) recursion is hard and 2) it requires a strong understanding of function calls, function scope, and return values.
Hi, I’m afraid I really struggle to focus on videos and they really don’t work for me to explain coding. I need to either be reading something, or doing it to learn.
No worries, here is old post about the previous step explain recursion in details.
and if you feel it’s spoiler, here is a news article about it
Okay, I have no idea what goes into modifiedArguments.
I had an idea but it didn’t work. So if I have 3 and 5, I need to get 3 to equal 5 to reach the base case. So I could divide 5 by 3, turn 2.5 into a whole number then add it to 3 to get 5.
But that didn’t work. I am really lost how to reach the base case. Nothing works.
Ignore the terminology for a second. I said that making an array of values from 7 to 42 is easy if you have an array of values from 7 to 41. How are those to arrays related?