From the course: Learning Functional Programming with JavaScript ES6+
Unlock this course with a free trial
Join today to access over 24,700 courses taught by industry experts.
Memoization - JavaScript Tutorial
From the course: Learning Functional Programming with JavaScript ES6+
Memoization
- [Speaker] Alright, so the third and final advanced functional concept that we're going to talk about here is a function called memoization. Sort of like memorization, but without the R. And interestingly enough, kind of similar as a concept. So let's create a new file and we'll say memoization.js. And in order to demonstrate this, what I want to show you is what happens if we try and run our recursion file, right? This Fibonacci function with a number much higher than 10. Let's in fact just try 10. Well, what you'll notice in this case is if we try and run our code with examples/recursion.js, it takes a long time to calculate that result. Now, instead of sitting around and waiting to see exactly how long that takes, what I'm going to do is stop it. And the reason why this is taking so long has to do with how this is being calculated, right? So you can picture that in order to calculate the 100th Fibonacci number, we need to calculate the 99th and the 98th Fibonacci numbers. However,…