Last active
March 28, 2017 14:24
-
-
Save Obre/565ee13da59167e41252b221660eb618 to your computer and use it in GitHub Desktop.
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
// looping variant | |
var power = function(base, exponent) { | |
var result = 1; | |
for (var count = 0; count < exponent; count++) | |
result *= base; | |
return result; | |
}; | |
console.log(power(2, 10)); | |
// recursive way (MUCH MUCH slower) | |
function power2(base, exponent) { | |
if (exponent == 0) { | |
return 1; | |
}else { | |
return base * power(base, exponent - 1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment