题解 | #数值的整数次方#
数值的整数次方
http://www.nowcoder.com/practice/1a834e5e3e1a4b7ba251417554e07c00
function Power(base, exponent) {
if (base == 0) {
return 0;
}
if (exponent == 0) {
return 1;
}
var res = 1;
if (exponent > 0) {
for (var i = 0; i < exponent; i++) {
res *= base;
}
return res;
} else {
for (var i = 0; i < (-exponent); i++) {
res = res / base;
}
return res;
}
}
module.exports = {
Power: Power,
};