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

Monday, December 10, 2012

Codeyear: Creating an array with recursion


//sample solution


// Here is the array we will store results in
var multiples = [];

function multiplesOf(base, i) {
  // Base case
  if (i===0) {
// Write the array multiples to the console
console.log(multiples);
  }
  // Recursive case
  else {
    multiples[i - 1] = base * i;
// Add a recursive function call
multiplesOf(base, i-1);
  }
}

multiplesOf(3,3);

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts