Quick actions

cmd+k|ctrl+k

Navigation

Languages

Funcs & objs #1

Snippet info

Language

JavaScript

Visibility

public

Author

paulkotov

Created

2017-10-10T19:27:49Z

Updated

2019-05-04T19:01:52Z

const memoize = fn => {
    let cache = {};
    return (...args) => {
        let stringifiedArgs = JSON.stringify(args);
        let result = cache[stringifiedArgs] = cache[stringifiedArgs] || fn(...args);
        return result;
    };
};

const getItemsMemoised = memoize((x, y) => x+y);
//const getItems = memoize((x) => x+2);
console.log(getItemsMemoised(2, 3));
INFO