Skip to content

Instantly share code, notes, and snippets.

@codebubb
Created December 7, 2015 13:24
Show Gist options
  • Select an option

  • Save codebubb/f78fb49428164e62826d to your computer and use it in GitHub Desktop.

Select an option

Save codebubb/f78fb49428164e62826d to your computer and use it in GitHub Desktop.
// 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