Skip to content

Instantly share code, notes, and snippets.

@odiak
Created April 16, 2011 01:35
Show Gist options
  • Save odiak/922757 to your computer and use it in GitHub Desktop.
Save odiak/922757 to your computer and use it in GitHub Desktop.
var sum = function () {
var memo = [];
return function (n, a, r) {
if (typeof memo[n] !== "undefined") {
return memo[n];
}
return memo[n] = (n === 1 ? a : a + r * sum(n - 1, a, r));
};
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment