Skip to content

Instantly share code, notes, and snippets.

@danieldram
Created March 30, 2017 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danieldram/6eba933f3cecce4c2d75aaf1fa3930a7 to your computer and use it in GitHub Desktop.
Save danieldram/6eba933f3cecce4c2d75aaf1fa3930a7 to your computer and use it in GitHub Desktop.
simple memoize sample
const memoize = (fn) => {
const cache = {}
return (...args) => {
const key = args.toString()
if(cache[key] == undefined){
cache[key] = fn(...args)
}
return cache[key]
}
}
let x = (num, num2) => num + 10 + num2
x = memoize(x) //Either mutate original function to memoized or could create memoized_x variable
var y = x(1,3)
console.log(y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment