Skip to content

Instantly share code, notes, and snippets.

@rochnyak-d-i
Created October 28, 2014 05:00
Show Gist options
  • Save rochnyak-d-i/863caf0074799c481b73 to your computer and use it in GitHub Desktop.
Save rochnyak-d-i/863caf0074799c481b73 to your computer and use it in GitHub Desktop.
JS шаблон мемоизации
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