We're a place where coders share, stay up-to-date and grow their careers.
You could also use a Map for that.
Map
const memoize = (callback) => { const cache = new Map(); return (...parameters) => { if (typeof cache.get(parameters) !== "undefined") { return cache.get(parameters); } cache.set(parameters, callback(...parameters)); return cache.get(parameters); } }
Why not just cache.get(parameters) !== undefined?
cache.get(parameters) !== undefined
👏🏼 I like this
You could also use a
Map
for that.Why not just
cache.get(parameters) !== undefined
?👏🏼 I like this