Skip to content

Instantly share code, notes, and snippets.

@ecaepsey
Created January 20, 2019 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecaepsey/b9a692485c60ac91c2d3fc7d4f8c5dda to your computer and use it in GitHub Desktop.
Save ecaepsey/b9a692485c60ac91c2d3fc7d4f8c5dda to your computer and use it in GitHub Desktop.
SUM OF PRIME
function sumPrimes(num) {
var count = []
for(var j = 0; j < num; j++) {
if(isPrime(j)) {
count.push(j)
console.log(count)
}
}
var sum = count.reduce((a, b) => a + b, 0);
return sum
}
function add(a, b) {
return a + b;
}
function isPrime(n) {
if(n == 2) {
return true
}
if(!Number.isInteger(n) || n < 2 || !(n%2)) {
return false
}
for(var i = 3; i <= n -1; i++) {
if(n % i == 0) {
return false
}
}
return true
}
console.log(sumPrimes(977))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment