Last active
October 3, 2016 15:30
-
-
Save AbdallaZaki/e6a8f13633f2ef25f9a41127010219ea 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
// https://projecteuler.net/problem=2 | |
var getSumOfEvenFibonacciNum = function (limit){ | |
var evenNum=2,prevEvenNum=0,sumOfEvenFibonacciNum=evenNum; | |
while (evenNum<=limit){ | |
var tempEvenNum=evenNum; | |
evenNum=(evenNum*4)+prevEvenNum; | |
if(evenNum>limit) break; | |
prevEvenNum=tempEvenNum; | |
sumOfEvenFibonacciNum+=evenNum; | |
} | |
return sumOfEvenFibonacciNum; | |
} | |
console.log(getSumOfEvenFibonacciNum(4000000)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment