Skip to content

Instantly share code, notes, and snippets.

@carlsednaoui
Last active December 15, 2015 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlsednaoui/5218024 to your computer and use it in GitHub Desktop.
Save carlsednaoui/5218024 to your computer and use it in GitHub Desktop.
Exponential calculation in JS
(function calc(number, power, sum) {
return power === 0 ? sum : calc(number, --power, (sum || 1) * number );
})(2, 10)
(function calculate(number, power, result, i) {
if (i === 10) { return; }
i++;
result = result * number;
console.log(result);
calculate(number, power, result, i);
})(2, 10, 1, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment