In this video, we are going to learn about recursion – what recursion is, how it works, and why it’s useful.
This video is part of a series – you’ll get a lot more out of it if you watch the other episodes before watching this one. You can find them here:
Recursion is when a function calls itself until it doesn’t.
That is seriously all recursion is. It’s really simple. A lot of people think that recursion is hard. The reason people think that recursion is hard is because all explanations of recursion use fibonacci numbers as an example, which is the worst example ever. If somebody tries to explain recursion to you using fibonnaci numbers, you must murder them. I understand that sounds rough, because they mean well, but
we really need to get rid of that, because it makes everyone think that recursion is hard, when it is actually easy.
Original source
35 responses to “Recursion – Part 7 of Functional Programming in JavaScript”
I'm cofused about what you say in 6:26 (my english is not very good).
Does not Bohm-Jacopini's theorem imply that every task accomplished by recursion can be accomplished by iteration.
Sorry if i'm mistaken.
Wonderful videos!!
Thanks.
Hey MPJ, in other tutorials i see they dont just call the function.. but they return the function in order to recurse.. whats the difference ? are both things the same?
"they must die"
God damnit man you had me in stitches. I love your videos. Thank you for being the best webdev channel in the whole wide world
“`
console.log('poop');
// this is my standard string to output
“`
Me too!
I wrote the same code, but it does not display results. It only gets information that "c is not defined".
What may be the problem ?
type type type (return 'poo…) backspace 'Let's start by returning an empty object'
Okay but how does this work with Fibonacci numbers?
14:37 until you run out of consonant.. or… sanity.. ???
Great channel, great series. Just great. Thanks for making these videos.
Even worse than the Fibonacci numbers example is the Towers of Hanoi D:
@funfunfunction
So, I know this is probably an advanced concept for this lesson, and I know you're doing this this way probably for simplicity…
but..
isn't this overly complex?
I mean complex like computer science complex (isn't this Θ(n log n) or Θn^2 )…
How would you do this in a more efficient way… something more linear?
The reason I'm curious is because if this were a loop, it would for sure be a loop within a loop within a loop (like how you said which is something that should obviously be avoided at almost all costs), but I don't think it would HAVE to be.
or is this not that complex and I'm just misunderstanding it?
Man I love your video!!. Ive been watching you since I started programming 4 years ago. THANK YOU so much for all your hard work. My only beef is I really don't agree that let is the new var, it kind of feels like the whole == or === debate.
I've wrote out the code, and you can find it here https://gist.github.com/anonymous/bc6c4024952ee48a87eec24ca31c363a
+1 for FF success
damn.. this thing is good
hi what fonts is that?
how can i consume recursion to flat and object into dot notation.
original
[{
email: "holly61@example.org",
mobile: "43539470287",
telephone: "34113036951",
fax: "34117930381",
is_favorite: false,
created_at: "2017-03-31 22:22:36",
updated_at: "2017-03-31 22:22:36",
hid: "37DyK",
h_client_id: "yKO4j",
client: {
ser: 5,
name: "Adwaa Alshujaa Est.",
hid: "yKO4j"
}
},]
into this
[{
email: "holly61@example.org",
mobile: "43539470287",
telephone: "34113036951",
fax: "34117930381",
is_favorite: false,
created_at: "2017-03-31 22:22:36",
updated_at: "2017-03-31 22:22:36",
hid: "37DyK",
h_client_id: "yKO4j",
client.ser: 5,
client.name: "Adwaa Alshujaa Est.",
client.hid: "yKO4j"
}
},]
it would be have been great if you could have walked through each of the recursive calls in your second example…
What was the stopping case for the last recursion example? What makes it stop calling itself? thanks!
LMAO, i saw you almost return 'poop'
props to you mpj for using a very basic example and then actually using a real life example that recursion solves! you the man! great video as always!
I used to work with scientists, helping to manage data, and this involved loading data from several files into a single report, or vice-versa and everywhere in between. (a great way to learn Python)
Then one day, I discovered that there was no regular pattern of where the source files would be. Recursion to the rescue.
btw, I'm circling back to these videos after that work experience, and they are the best evar. Just recommended your channel to a co-worker.
Re "Curse" ion
I would like to say, the function of makeTree() is really smart designed.
Your videos are awesome mate ! Keep it up 🙂 I would surely share this video with the fibonacci guys 😀
clear and simple. well explained man.
i think you must now, npm install babel-preset-es2015
Love your videos, but just a suggestion …
I would use terms like "Base Case" just because if any of your viewers google more information about recursion they can put it together.
" and null is for.." what?! did he say magic. 12:21
if you say so.. i have to kill him
Hello! one question… in functional programming changing a var value is not a good practice, in your example "let node = {}" is changing every time the recursion is executed… is there another way to implement this example without this feature?. Thanx
Nice tutorial! Now you have to use npm install -g babel-cli
This was a great tutorial! I was so lost trying to figure out how to use this on a project, your category example was exactly what I needed. I come from a database driven background and I'm seriously struggling with the unstructured nature of javascript and understanding why you do things a certain way so all the "math" examples given from teachers and all other tutorials are not helpful to me at all, I do better dissecting working code to understand it properly and see how the functions are built out in conjunction with one another, that is another place I'm trying to master, I will browser the rest of your videos now, but this was super helpful!
Loving your functional programming series! Awesome work.
i honestly don't understand why they call them recursive functions and not just "loop functions", because that's essentially all they are, loops in the form of a function.