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

Sunday, December 9, 2012

Codecademy: Codeyear Arguments in recursion


//sample solution


function factorial(n) {
  // Termination condition to prevent infinite recursion
  if (n < 0) {
    console.log("Can't make a factorial from a negative number.");
    return;
  }
  // Base case
  if (n === 0) {
    return 1;
  }
  // What's wrong with this picture? Why won't this recursion work? => factorial(n)
  return n * factorial(n-1);
}

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts