Skip to content

Instantly share code, notes, and snippets.

@framingeinstein
Created August 7, 2018 14:10
Show Gist options
  • Save framingeinstein/115d00d6a874338caeb3e003122be41a to your computer and use it in GitHub Desktop.
Save framingeinstein/115d00d6a874338caeb3e003122be41a to your computer and use it in GitHub Desktop.
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