Last active
August 29, 2015 14:16
-
-
Save alyssonbruno/1eafb2046f0cd66eaec8 to your computer and use it in GitHub Desktop.
My 2 cents
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// global scope | |
(function(){ | |
// outer scope | |
var fibonacci = function(){ | |
my_return = "0, "; | |
current_number = 0; | |
minus_one_order = 0; | |
minus_two_order = 0; | |
max_order=12; | |
for(current_order = 1;current_order<=max_order;current_order+=1){ | |
if(current_order===1){ | |
current_number = 1; | |
} | |
else{ | |
current_number = minus_one_order+minus_two_order; | |
} | |
minus_two_order = minus_one_order; | |
minus_one_order = current_number; | |
my_return += current_number.toString()+(current_order<max_order?', ':''); | |
} | |
return my_return; | |
} | |
console.info(fibonacci()); | |
})(); | |
// global scope | |
(function(nth){ | |
// outter scope | |
var fibonacci = function(max_order){ | |
max_order = max_order==null?12:max_order; | |
current_number = 0; | |
minus_one_order = 0; | |
minus_two_order = 0; | |
for(current_order = 1;current_order<=max_order;current_order+=1){ | |
if(current_order===1){ | |
current_number = 1; | |
} | |
else{ | |
current_number = minus_one_order+minus_two_order; | |
} | |
minus_two_order = minus_one_order; | |
minus_one_order = current_number; | |
} | |
return current_number; | |
} | |
console.info(fibonacci(nth)); | |
// the call below is going to have a result with the position | |
// 2x ahead of the one passed to nth | |
console.info(fibonacci(nth*2)); | |
})(10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment