-
-
Save ecaepsey/b9a692485c60ac91c2d3fc7d4f8c5dda to your computer and use it in GitHub Desktop.
SUM OF PRIME
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) { | |
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