Created
August 17, 2016 11:14
-
-
Save MeyCry/5adcf1ac6741a282f8bb7fe3c572b560 to your computer and use it in GitHub Desktop.
fib
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
var initialFirst = 0; | |
var initialLast = 1; | |
var index = 0; | |
var calcFib = function selfCall (num) { | |
if (num < 1) return; | |
index++; | |
var result = initialFirst + initialLast; | |
initialFirst = initialLast; | |
initialLast = result; | |
if ((num - 1) === index) { | |
return result; | |
} | |
return selfCall(num); | |
}; | |
function fib(count) { | |
if (count < 2) { | |
return count; | |
} | |
return fib(count - 1) + fib(count - 2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment