I'm struggling to solve a question on big front end, link. The task is to implement a general memoization function. I came across this solution, but I'm having trouble understanding what the resolver is/does. First time I've come across that term and searching google was unhelpful.
function memo(func, resolver = (...args) => args.join('_')) {
const cache = new Map();
return function(...args) {
const cacheKey = resolver(...args);
if (cache.has(cacheKey)) {
return cache.get(cacheKey);
}
const value = func.apply(this, args);
cache.set(cacheKey, value);
return value;
}
}