Skip to content

Instantly share code, notes, and snippets.

@Restuta
Created October 24, 2017 17:39
Show Gist options
  • Save Restuta/89193bd17e57c1339fdc4888b072d7ed to your computer and use it in GitHub Desktop.
Save Restuta/89193bd17e57c1339fdc4888b072d7ed to your computer and use it in GitHub Desktop.
function memoize(foo) {
let cache = {}
return args => {
if(cache[args]) {
return cache[args]
}
const executionResult = foo(args)
cache = {
...cache,
[args]: executionResult
}
return executionResult
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment