Memoization is an optimization technique used primarily to speed up computer programs by storing the results of expensive function calls and returning the cached result when the same inputs occur again
In other words, Memoization is a way for a function to remember or cache the results. Given an expensive function that takes a long time to compute for the same results, create a memorization function that can cache results and outputs them with no time at all.
memo
function that takes in a function
and computes it. If the parameters are same and you already have the results in your cache, return the memoized results.Product
function to mimic an expensive function calculation.Click to reveal
Your cache can be a simple object that can store input parameters of the product
function that needs to be calculated.
Click to reveal
Keep in mind the basics of call()
, apply
, and bind()