Created
August 7, 2018 14:10
-
-
Save framingeinstein/115d00d6a874338caeb3e003122be41a to your computer and use it in GitHub Desktop.
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
function fib(maximum){ | |
var n0 = 1, n1 = 2, next = 0, sum = 1; | |
console.log(n0, n1) | |
next = n0 + n1; | |
while(next < maximum){ | |
n0 = n1; n1 = next; | |
if(next % 2 !== 0){ | |
sum = sum + next; | |
} | |
next = n0 + n1; | |
} | |
return sum; | |
} | |
console.log(fib(2000000)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment