<_html> JavaScript Question 8081

How to implement memoization in JavaScript efficiently

Published 2 hours ago by user3055001

javascript - react performance function

What are best practices for implementing memoization in JS?


function memo(func) {
    const cache = {};

    return (arg) {
        if (cache.key in cache) {
            return cache[arg]
        }

        const answer = func(arg);
        return cache[arg] = expensiveFunction()
    }
}

What are ways to improve the memoization efficiency

3 Answers

106 views

``` ```