Skip to content

Instantly share code, notes, and snippets.

@kingsidharth
Created March 30, 2012 12:56
Show Gist options
  • Save kingsidharth/2251330 to your computer and use it in GitHub Desktop.
Save kingsidharth/2251330 to your computer and use it in GitHub Desktop.
Calculate power of something in js
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