Breaking News
Home » WEBSITE DEVELOPMENT » Recursion – Part 7 of Functional Programming in JavaScript

# Recursion – Part 7 of Functional Programming in JavaScript

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.

source

## What's New in Node 10 "Dubnium"

Node.js 10.0.0 is the seventh major Node.js release since the launch of the Node.js Foundation. …

1. Rather than using several nested loops, you can run two separate loops, one to get a list of all the parents and then another to pass the children into their parents.

2. I need your brain good sir. I feel like a recursion myself. Going over and over and over [reaches limit of stack]

3. Out of curiosity, is there a solution to do this using the Reduce() function?

4. @5:10 why semicolon after return; but not lines 3 and 4. is a return line without a semicolon more likely to crash JS JIT compiler?

5. I LOVE Fibonacci series and all kinds of math relating to nature. Fibonacci must live, you must renounce or die. (p.s. I think i learnt it first in like yr 8 or 9 math class, not advanced at all).

6. "and null is for magic…"

7. yes, arrow functions are everywhere in the "future". You're a wizard 😉

8. omg this made me laugh so hard. they must die!

9. a rooster died and on his gravestone was written a rooster died and on his …

10. Any chance of making a data structure or algorithm series?

11. Tips on flattening an array using these methods?

12. I'm so glad we share the same 'standard string to output'. It's always console.log('poop') or console.long('ting')

13. Yes! Great job. Why when I move the console.log()
underneath the 'countDownFrom(num -1). It outputs a count up 1-10?

Also Do you have any examples teaching assorting arrays, and working with algorithms using ES6 or vanilla JS?

14. I'm just learning JS, and we're starting with 5 so that we understand basic concepts before learning 6, so while trying to understand this video on recursion, using 6 threw me off as I'm already trying to just grasp recursion and 5. Also don't know what babel is lol, we use repl so far. Thanks for the video though, probably will understand it better in a few weeks or so. :)))

15. @funfunfunction THANK YOU SO MUCH! Someone else tried explaining recursion to me, and it just sounded awfully complicated, and gave me reasons to AVOID recursion altogether. You've helped by boiling down the concept to it's raw, no-nonsense core.

I now just have to expand on this a little to apply it to a study exercise, which shouldn't be terribly difficult 🙂

16. 3:00 Nitpicking on my part, but used `const` not `let` whenever you are not going to reassign to that variable. It's a signal that it's not meant to be reassigned and throws if you accidentally do. Otherwise, use `let`. Never use `var` because it can confuse you with the order of operations involving its "hoisting" behavior.

17. I only understood this example after the second time watching this (y) You're a genius

18. Hi boss! I'm watching this from the "near future" (ES6 still not the standard … but it should) and its not just awesome you explanations and your work, is that you "quoted" ff7 sounds as the function worked ? you are the boss !! thanks for the work in the hole series and channel. Kudos from Uruguay.

19. I love your channel! Just I have to say it, everything can be implemented with fors. You can implement your own stack in an array to know the pending nodes to process. Of course, it would be much much much characters long (to use the metric of this series) and really more complex and bug. I think this little lie is perfectly worth it for the clarity in your explanation.

20. so much friendlier way to introduce this concept of recursion!

21. Super Video! Loved it. Was confused about how to get this tree format with recursion, watching this video made everything clear. Plus laughed through out!

22. 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.

23. 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?

24. "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

25. “`
console.log('poop');
// this is my standard string to output
“`
Me too!

26. 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 ?

27. type type type (return 'poo…) backspace 'Let's start by returning an empty object'

28. Okay but how does this work with Fibonacci numbers?

29. 14:37 until you run out of consonant.. or… sanity.. ???

30. Great channel, great series. Just great. Thanks for making these videos.

31. Even worse than the Fibonacci numbers example is the Towers of Hanoi D:

32. @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?

33. 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.

34. 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,
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.hid: "yKO4j"
}
},]

35. it would be have been great if you could have walked through each of the recursive calls in your second example…

36. What was the stopping case for the last recursion example? What makes it stop calling itself? thanks!

37. LMAO, i saw you almost return 'poop'

38. 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!

39. 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.

40. I would like to say, the function of makeTree() is really smart designed.

41. Your videos are awesome mate ! Keep it up 🙂 I would surely share this video with the fibonacci guys 😀

42. clear and simple. well explained man.