A Practical Guide to Algorithms with JavaScript

Recursive Factorial & Memoize Exercise

A Practical Guide to Algorithms with JavaScript

Check out a free preview of the full A Practical Guide to Algorithms with JavaScript course

The "Recursive Factorial & Memoize Exercise" Lesson is part of the full, A Practical Guide to Algorithms with JavaScript course featured in this preview video. Here's what you'd learn in this lesson:

In this exercise, students write their own recursive factorial method.


Transcript from the "Recursive Factorial & Memoize Exercise" Lesson

>> Bianca: So we're gonna hop into our next exercise which is going to be you writing your own recursive factorial method. You can reference the past slides if you'd like on factorial, but try not to copy the recursive solution. I recommend looking at the iterative solution, maybe looking at the slide where it's like, this is the pattern, but not copying directly the factorial solution.

You might find that hearing me talk about it is, feels very different than actually implementing it. So I wanna give you that experience of the two differences there. There is a false sense of progress, when you hear someone talking about a concept, especially around programming. And it feels like, I got it, the way she explains seems like, easy.

But it's a whole different experience when you have to implement it from scratch, and you need to reason through every line of code. So my advice is to not write some code, run it. Write some code, run it, and see what happens, but instead make sure that you're paying attention to every line of code that you're writing.

Maybe even play the call set game with yourself. I actually do that when I get stuck on something, especially recursion. I play the call set game with myself, just to see that I'm reasoning correctly about how my code is executing. So, with Task 1 do that, and then, if you have time, and for our more advanced people, you can combine this with your memo function that we wrote earlier, and you can memoize your factorial.

Cuz the factorial is doing a lot of repeated calculations. And you can just pass it to your memo function, or you can use your memo function in a creative way to cache your factorial results.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now