Tell us what’s happening:
i’m passing two out of three requirements but i noticed that my array is coming short of some values and when i’m summing up the array’s values the returned value that i get isn’t the expected one. would anyone put in the right direction ?
Your code so far
function sumPrimes(num) {
function primeNum(n){
for(let i = 2; i <= Math.sqrt(n); i ++){
if(n % i === 0){
return false
}
}
return true;
}
let arr = [2];
for(let i = 3; i < num; i+= 2){
if(primeNum(i) && primeNum(i) <= num){
arr.push(i)
}
}
return arr.reduce((a, b) => a + b);
}
console.log(sumPrimes(977));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36
.
Challenge: Sum All Primes
Link to the challenge: