Skip to content

Instantly share code, notes, and snippets.

@nefarioustim
Created June 5, 2011 14:55
Show Gist options
  • Save nefarioustim/1009018 to your computer and use it in GitHub Desktop.
Save nefarioustim/1009018 to your computer and use it in GitHub Desktop.
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
for(
var sum = 0, f1 = 1, f2 = 2, next;
f2 < 4E6;
f2 & 1 || (sum += f2), next = f1 + f2, f2 = (f1 = f2, next)
);
console.log(sum);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment