Recursion - Part 7 of Functional Programming in JavaScript

preview_player
Показать описание
💖 Support the show by becoming a Patreon

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.

💛 Follow on Twitch
We record the show live Mondays 7 AM PT

💛 Fun Fun Forum

💛 mpj on Twitter

💛 CircleCI (Show sponsor)
Robust and sleek Docker-based Continuous Integration as a service. I used CircleCI prior to them becoming a sponsor and I love that their free tier is powerful enough for small personal projects, even if they are private. Use this link when you sign up to let them know you came from here:

💛 Quokka (Show sponsor)
Wonder how MPJ evaluates JavaScript inline his editor. Quokka is the answer - use this link when you buy to let them know you came from here:

💛 FUN FUN FUNCTION
Since 2015, Fun Fun Function (FFF) is one of the longest running weekly YouTube shows on programming 🏅 thanks to its consistency and quality reaching 200,000+ developers.

🤦‍♂️ The Failing Together concept is what makes FFF unique. Most coding content out there focus on step-by-step tutorials. We think tutorials are too far removed from what everyday development is like. Instead, FFF has created a completely new learning environment where we grow from failure, by solving problems while intensively interacting with a live audience.

Tutorials try to solve a problem. Failing Together makes you grow as a developer and coworker.

📹 Each show is recorded live on Twitch in a 2-hour livestream on Mondays. The host, assisted by the audience, is tasked to complete a programming challenge by an expert guest. Like in the real world, we often fail, and learn from it. This, of course, reflects what the audience identifies with, and is one of the most praised aspects of the show.

⏯ On Fridays, an edited version of the show is adapted for and published on YouTube.

Content Topics revolve around: JavaScript, Functional Programming, Software Architecture, Quality Processes, Developer Career and Health, Software Development, Project Management
Рекомендации по теме
Комментарии
Автор

I think everyone should watch this video again.
And again.
And again.

coolworx
Автор

let categories = [
{ id: 'animals', parent: null },
{ id: 'mammals', parent: 'animals' },
{ id: 'cats', parent: 'mammals' },
{ id: 'dogs', parent: 'mammals' },
{ id: 'chihuahua', parent: 'dogs' },
{ id: 'labrador', parent: 'dogs' },
{ id: 'persian', parent: 'cats' },
{ id: 'siamese', parent: 'cats' }
];

// for the active learners

nodidog
Автор

Things I love in your videos so far....
1) Seeing you code 'live', and explain what you are doing... because putting pre-written code on the screen makes it that much more difficult to grasp.
2) Answering the most important question.... the "Why" you want to learn the stuff being shown.
3) The summary at the end (reinforces the learning).
4) How you often describe stuff not in the main topic of the video, but very useful nonetheless (like 'let')

Things I would like to see in future videos...
1) All the above, of course
2) Suggestions for deepening the knowledge on the material, using outside resources. Perhaps extra stuff to watch, read, or try ourselves.

Thank you

evolopterus
Автор

@primosoma Absolutely, you're right on all accounts. One teacher once told me a great tidbit on pedagogy - it's about telling a big lie and then gradually reducing it by adding details during the semester. :) I know that the Fibonacci example is used because of it's completeness, but when it comes to explaining and communicating complicated concepts, perfect correctness often makes the example so unwieldy that it comes the expense of clarity. Humans are really good at gradually incorporating new details into their thought models, but need to expend a lot of energy on big things like functions calling functions, so it's better to try to skip as many details as possible initially imho.

funfunfunction
Автор

"When somebody tries to explain recursion to you using fibonacci numbers... YOU. MUST. MURDER them." LOL

WalkerLeite
Автор

Golden QUOTE: "When somebody tries to explain recursion to you using Fibonacci numbers ... You MUST murder them!" ~ love this!!! the amount of times I have been given interview test using Fibonacci numbers in scala examples I wish I had a t-shirt on with your picture & this quote ... thank You - AWESOME!

MarkW
Автор

Another great explanation of JS basics.

I'd like to see how you explain .call(), .apply() and .bind().

JnsWndlmth
Автор

Best darn explanation of recursion EVER. Used it to help my 12-year old daughter understand the concept. Bingo ... she could replicate a simplified version of your makeTree example once she saw the countDown portion of your video. You are a gifted instructor! Thank you (now we just have to get Dad using ECMAScript 6 ...

AzulWells
Автор

I was just reading a post that mentioned a story: their professor in school said that students that didn't get recursion will likely never get it. Sounds like a closet fibonacci kinda professor lol. GET EM !!! funfunfuncion is the BEST youtube coding series

greatcreate
Автор

Stephen Florian Thank you for your interest in my ficus! The tree is a Ficus Microcarpa Ginseng. It is placed in front of a window facing south (my apartment is located in the southern part of Sweden). 

I tend to water it once a week (recording the episodes provides a handy cue for this) by submerging the pot completely in water and letting it drain for a while (approximately 30 minutes) afterwards.

The tree has been doing very well for quite some time (I don't quite remember when I bought it, but it's around a year ago) Unlike my previous bonsai trees, this seems to be very resilient - most likely a very conscious decision by IKEA, where I bought it.

Where I would need advice is re-planting and nutrition, I have no clue about that. My girlfriend is a florist and could probably help me, but I would very much prefer to rely on my YouTube community for this because it would be awesome.

funfunfunction
Автор

I understood straight away! Can't believe it.... I've been watching video after video and the example problems were way too complex - it seemed they were becoming more and more complex lol. Thanks for the simple break down.

chriscarey
Автор

I absolutely love your videos. Your way of teaching is great and kept me interested when I was still very clueless about what took place on the screen. I first came to you videos a few months ago when I didn't get much of anything but wanting to get an idea of what i could do with this language. It's a great feeling coming back to them now a second time (and there will be a third, fourth...) and now being able to understand more and to slowly implement some of this in my own code.
I'm a Finn so making me love a Swede instantly is quite a an achievement by you :D

natyalim
Автор

I just started your videos and you're a genius. Ive started as a .net and no front end and slowly converted to more front end and I'm always learning!

melikai
Автор

I have watched 3 different videos before this one trying to learn and understand Recursion....THANK GOD FOR THIS VIDEO!!! I wish the other were this clear. Due to this video, I definitely will be subscribing and sharing on Twitter. And this video is 3 years old (smile)

alicialivingston
Автор

I started learning JS about 3 months ago. I came across your videos today, and I am binge watching. I would not have grasped a fraction of this a month ago, and I just realized I am starting to understand base syntax to basically read what you are doing. I appreciate the "Aha!"moment. You are a great teacher, everything you do appears to have the student in mind with the right amount of push forward.

SAHD_Guy
Автор

So great to see someone explaining this so lovely and simple. Too many times explanations are "over engineered". Been a JavaScript developer for 5 years...still learn new things from you!

claudiad.
Автор

Truly one of the most fascinating topics in computer science. Thanks MPJ, and godspeed on your new journey

johnmirra
Автор

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!

themigga
Автор

Thank you for such a simple explanation. My story: a couple days ago I decided to pick up "Eloquent JavaScript". I blazed through the first couple chapters, and then was immediately road-blocked by a small section on Recursion in Chapter 3 (quite a convoluted way to introduce a concept, if you ask me—sorry Marijn Haverbeke). However! After watching your video here, I immediately solved the end-of-chapter exercise on recursion and was able to move on :) Thanks again.

andrewrubin
Автор

i remember watching this functional programming series awhile back and seeing this example... cool implementation, but after coming across hierarchical data in a real life example (rows returned from a SQL query) and trying to turn it into an Object tree MAN is this useful! Thank you so much!

julianjacobs