Last active
December 15, 2015 06:39
-
-
Save carlsednaoui/5218024 to your computer and use it in GitHub Desktop.
Exponential calculation in 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 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