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

Thursday, December 6, 2012

Codecademy: Codeyear Talking about Functions


//sample solution


var Wibble = {
 
  Wobble: function(a, b) {
    if(a===b)
        //if the variables are equal return 0
        return 0;
    else {
        //decrement the larger of the 2 values
        if (a>b) {
            a--;
        } else {
            b--;
        }
        //call this function again with the decremented values
        //once they are equal the functions will return up the stack
        //adding 1 to the return value for each recursion
        return Wibble.Wobble(a,b)+1;
    }
  },
  Wob: function(a, b) {
  return Math.abs(a-b);
  }
};
console.log(Wibble.Wob(7,11));

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts