1.0.1-alpha • Published 3 years ago

simple-cache-function v1.0.1-alpha

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

simple-cache-function

Saves the result of the function. With the same arguments, the function returns the stored result.

Install

Install with npm:

$ npm install --save simple-cache-function

Usage

const { memoize } = require('simple-cache-function');

function fibonacci(n) {
    if (n <= 1) {
        return 1
    }
    return fibonacci(n - 1) + fibonacci(n - 2);
}

const fibonacciMemo = memoize(fibonacci);

console.log(fibonacciMemo(6)); //=> 13

Author

Rostislav Kalyuzhny