Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save codebubb/dad177fe246e18f74a3e to your computer and use it in GitHub Desktop.
// Bonfire: Sum All Primes
// Author: @codebubb
// Challenge: http://www.freecodecamp.com/challenges/bonfire-sum-all-primes#
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function sumPrimes(num) {
var primes = [];
for(var i=2; i<=num; i++){
if(isPrime(i)) primes.push(i);
}
return primes.reduce(function(a,b){
return a+b;
});
}
function isPrime(n){
for(var i=2; i<n; i++){
if(n % i === 0) return false;
}
return true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment