WBE_Praktikum_8/memo.js

13 lines
258 B
JavaScript
Raw Permalink Normal View History

2022-11-17 09:58:26 +01:00
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
}
}