Memoization

Caching a function's result so repeated inputs can return it without recalculation.

What is Memoization in JavaScript?

Memoization — Caching a function's result so repeated inputs can return it without recalculation.

const cache = new Map();

function remember(key, calculate) {
    if (!cache.has(key)) {
        cache.set(key, calculate());
    }

    return cache.get(key);
}

Level: Freelancer · More JavaScript terms at this level

Updated