Created
October 19, 2017 14:12
-
-
Save kipanshi/8126958be6a46cac8ed3c5e6b76be978 to your computer and use it in GitHub Desktop.
Fibbonaci Fast dobule Algo
This file contains 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 yourself = { | |
fibonacci: function(n) { | |
return this._fib(n)[0] | |
}, | |
_fib : function(n) { | |
if (n === 0) { | |
return [0, 1] | |
} else { | |
let half = this._fib(Math.floor(n / 2)); | |
let a = half[0] | |
let b = half[1] | |
let c = a * (b * 2 - a) | |
let d = a * a + b * b | |
if (n % 2 === 0) { | |
return [c, d] | |
} else { | |
return [d, c + d] | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment