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

Sunday, December 9, 2012

Codecademy: Codeyear Unpacking the stack, Part 1


//sample solution


function factorial(n) {
    if (n === 1) {
return 1;
} else {
return n * factorial(n-1);
}
}

// 1. Create an empty array called "stack"
var stack = []
// 2. Define the function countDown(int)
function countDown(int){
//base case
if(int===1){
stack.push(int);
return 1;
} else {
//recursive case
   stack.push(int);
countDown(int-1);
return int;
}
}
// 3. Call countDown() on an integer
countDown(10);

// And now let's have a look at that stack:
console.log(stack);

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts