Created
November 6, 2011 04:31
-
-
Save zerojuan/1342477 to your computer and use it in GitHub Desktop.
Project Euler 2. Comments.js
This file contains hidden or 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 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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
'i' is no longer needed in the for loop. A while loop is more suitable in this situation.