Created
February 13, 2015 09:54
-
-
Save martinpinto/3a6b6da137e561f24e4f 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
/* iterative fibonacci sequence O(n) */ | |
function fibo(n) { | |
var fiboArr = [0, 1]; | |
for (var i = 1; i < n; i++) { | |
fiboArr.push(fiboArr[i - 1] + fiboArr[i]); | |
} | |
return fiboArr; | |
} | |
function fiboSum(n) { | |
var sum = 0, arr = fibo(n); | |
for (var i = 0; i < arr.length; i++) { | |
if (arr[i] > n) | |
break; | |
if (arr[i] % 2 == 0) { | |
sum += arr[i]; | |
} | |
} | |
return sum; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment