Socket
Socket
Sign inDemoInstall

memoization

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

memoization

Straightforward implementation of memoization.


Version published
Weekly downloads
186
increased by55%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status

memoization

Straightforward implementation of memoization in javascript

Exemple Usage

var memoize = require("memoization");
var fib = memoize(function(n){return n<2 ? n : fib(n-1) + fib(n-2);});

Code

function memoize(f) {
  var dict = {};
  return function() {
    var args = JSON.stringify(arguments);
    if(dict.hasOwnProperty(args)) return dict[args];
    var res = f.apply(this, arguments);
    dict[args] = res;
    return res;
  }
}

if (typeof module === "object") module.exports = memoize;

Keywords

FAQs

Package last updated on 02 Nov 2016

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc