Edited fibonacci.js

Added another possible solution that doesn't use a loop.
This commit is contained in:
Bradley Peterson 2019-10-11 11:46:17 -05:00 committed by GitHub
parent 01aace24b1
commit 0d7c05485b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 0 deletions

View File

@ -10,4 +10,15 @@ const fibonacci = function(count) {
return b; return b;
}; };
/* Another possible solution
const fibonacci = function(num) {
const goldenRatio = (1 + Math.sqrt(5)) / 2;
if(num < 0) return "OOPS";
return Math.floor((goldenRatio**num) / Math.sqrt(5) + 0.5);
}
*/
module.exports = fibonacci
module.exports = fibonacci; module.exports = fibonacci;