//sample solution
var power = function(base, exponent){
if(exponent===0){
return 1;
} else {
return base * power(base, exponent - 1);
}
};
console.log(power(2,3)===8);
console.log(power(2,0)===1);
console.log(power(10,2)===100);
//note, power(0,0) will fail the test since it evaluates to 1
No comments:
Post a Comment