Skip to content

Instantly share code, notes, and snippets.

@kis
Forked from rochnyak-d-i/memoization.js
Created December 23, 2015 10:41
Show Gist options
  • Save kis/2931ac923629f18d5fa6 to your computer and use it in GitHub Desktop.
Save kis/2931ac923629f18d5fa6 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