Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save patrickcurl/12db0e773975104d3c79 to your computer and use it in GitHub Desktop.
Save patrickcurl/12db0e773975104d3c79 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/patrickcurl 's solution for Bonfire: Sum All Primes
// Bonfire: Sum All Primes
// Author: @patrickcurl
// Challenge: http://www.freecodecamp.com/challenges/bonfire-sum-all-primes
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function sumPrimes(num) {
if(num === 1){
return 0;
}
if(isPrime(num) === false){
return sumPrimes(num-1);
}
if(isPrime(num) === true){
return num + sumPrimes(num-1);
}
}
function isPrime(num){
for(i=2; i<= num;i++){
if(num % i === 0 && num != i){
return false;
}
}
return true;
}
sumPrimes(10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment