Socket
Book a DemoInstallSign in
Socket

memoizejs

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

memoizejs

A faster JavaScript memoizer

latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

Memoize.js

A faster JavaScript memoizer

Whilst not new by any means, memoization is a useful optimization technique for caching the results of function calls such that lengthy lookups or expensive recursive computations can be minimized where possible.

The basic idea is that if you can detect an operation has already been previously completed for a specific set of input values, the stored result can instead be returned instead of repeating the operation again.

Some of the problems memoization can help optimize include: recursive mathematics, algorithmic caching of canvas animation and more generally, any problems which can be expressed as a set of calls to the same function with a combination of argument values that repeat.

Usage

Imagine having a function you want to memoize, like running the Fibbonacci sequence:

var fib, fiborg;

fiborg = fib = function (x) {
  if(x < 2) return 1; else return fib(x-1) + fib(x-2);
}

We can then memoize it as follows:

fib = memoize(fiborg);
fib(20);

License

Released under an MIT license.

Keywords

memoize

FAQs

Package last updated on 16 Aug 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts