WBE_Praktikum_8/memo.js

13 lines
258 B
JavaScript

function memo (func) {
let cache = new Map()
return (...args) => {
let argStr = args.toString(), result
if ((result = cache.get(argStr)) === undefined) {
result = func(...args)
cache.set(argStr, result)
}
return result
}
}