DEV Community

Jack Cole
Jack Cole

Posted on

3 1

Learning Memoization in Javascript Part 2

After doing some research on how to implement memoization in a function with multiple arguments I realized this is a pretty unusual situation that will rarely occur...

In my last post I went over implementing memoization in javascript using the fibonacci sequence as an example. However, in that example our function only utilized a single argument. But how do we memoize when a function needs to track multiple arguments?

Implementation

In my example I'm going to use a nested map object. The map will have multiple dimensions and store the fibonacci data in the dimension that matches the specific method call. Remember, this is just an example displaying how we would go about doing this.

Also going on a short tangent, notice how I use map objects instead of a regular hash. Javascript has a map object, learn to use it! You can read more about that here.

Memoization Multiple Functions

Thanks for reading! I know that this is a pretty niche situation but memoization is a good skill to know and could come in handy in the future! The code for this post and my last post can be found here.

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (1)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay