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.

Original source


35 responses to “Recursion – Part 7 of Functional Programming in JavaScript”

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

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

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

  4. 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"
    }
    },]

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

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

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

Leave a Reply