Created
March 30, 2012 12:56
-
-
Save kingsidharth/2251330 to your computer and use it in GitHub Desktop.
Calculate power of something 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
var power = function (base, exponent) { | |
if(exponent === 0) { | |
return 1; | |
} else { | |
var result = 1; | |
for (var i = 0; i < exponent; i++) { | |
result = result * base; | |
} | |
return result; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment