Last active
January 5, 2020 02:52
-
-
Save germancutraro/9401c59bf850ff9fb028711bb19fdb01 to your computer and use it in GitHub Desktop.
Easy memorizing function js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const calcs = {}; | |
const sum = (a,b) => { | |
let key = 'sum' + (a+b).toString(); | |
if ( key in calcs ) | |
return 'found: ' + calcs[key] | |
let total = a + b; | |
total--; | |
total++; | |
calcs[key] = total; | |
return total; | |
} | |
sum(2, 2) | |
sum(2, 3) | |
let memo = sum(2, 3) | |
console.log(memo) | |
console.log(calcs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment