Skip to content

Instantly share code, notes, and snippets.

@zerojuan
Created November 6, 2011 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zerojuan/1342477 to your computer and use it in GitHub Desktop.
Save zerojuan/1342477 to your computer and use it in GitHub Desktop.
Project Euler 2. Comments.js
function sumEvens(value){
var curr = 0;
var n1 = 0;
var n2 = 1;
var result = 0;
for(var i=2; curr<value; i++){
curr = (n1 + n2);
n1 = n2;
n2 = curr;
if(curr%2==0)
result += curr;
}
return result
}
@zerojuan
Copy link
Author

zerojuan commented Nov 6, 2011

'i' is no longer needed in the for loop. A while loop is more suitable in this situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment