Created
July 24, 2015 16:01
-
-
Save wendy0402/4051a7c888d98e260814 to your computer and use it in GitHub Desktop.
summarize prime number, but to check whether it is prime or not, based on previous prime number
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
function sumPrimes(num) { | |
prime = [2,3]; | |
sum = 2 + 3; | |
for(n = 4; n <= num; n++){ | |
var prime_flag = true; | |
for(prime_d = 0; prime_d < prime.length; prime_d++){ | |
if(n % prime[prime_d] === 0){ | |
prime_flag = false; | |
} | |
} | |
if(prime_flag){ | |
sum += n; | |
prime.push(n); | |
} | |
} | |
return sum; | |
} | |
sumPrimes(10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment