Created
December 7, 2015 13:24
-
-
Save codebubb/f78fb49428164e62826d to your computer and use it in GitHub Desktop.
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
| // Bonfire: Sum All Odd Fibonacci Numbers | |
| // Author: @codebubb | |
| // Challenge: http://www.freecodecamp.com/challenges/bonfire-sum-all-odd-fibonacci-numbers# | |
| // Learn to Code at Free Code Camp (www.freecodecamp.com) | |
| function sumFibs(num) { | |
| return fib(num).reduce(function(a,b){ | |
| return b % 2 ? a + b : a; | |
| }); | |
| } | |
| function fib(n){ | |
| var arr = [1]; | |
| for(var i=1; i <= n; i = arr[arr.length - 2] + arr[arr.length - 1]) arr.push(i); | |
| return arr; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment