Quotes help make search much faster. Example: "Practice Makes Perfect"

Monday, December 3, 2012

Codecademy: Codeyear Recursive: Part 4


//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


This is an example of scrolling text using Javascript.

Popular Posts