12 lines
204 B
JavaScript
12 lines
204 B
JavaScript
export function memoize(f) {
|
|
const memo = {};
|
|
|
|
function g(...args) {
|
|
if (!(args in memo)) {
|
|
memo[args] = f(...args);
|
|
}
|
|
return memo[args];
|
|
}
|
|
|
|
return g;
|
|
} |