Created
October 28, 2014 05:00
-
-
Save rochnyak-d-i/863caf0074799c481b73 to your computer and use it in GitHub Desktop.
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
function calculation(x, y) | |
{ | |
var key = x.toString() + "|" + y.toString(); | |
var result = 0; | |
if (!calculation.memento[key]) | |
{ | |
for (var i = 0; i < y; ++i) result += x; | |
calculation.memento[key] = result; | |
} | |
return calculation.memento[key]; | |
} | |
calculation.memento = {}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment