Hard
How to Implement Memoization in JavaScript Using Closures for Single Execution Functions
How can you ensure that the function expensiveCalculation runs only once even if it’s called multiple times, and returns the cached result?
1const expensiveCalculation = () => {2 console.log("Calculating...");3 return 42;4};56const runOnce = (fn) => {7 // Your implementation here8};910const calculate = runOnce(expensiveCalculation);11console.log(calculate());12console.log(calculate());