function sumPrimes(num) {
// Check all numbers for primality
//initializes empty array
let myArr =[];
//iterates through numbers from two to the given input
for (let i= 2; i<=num; i++){
//if i isn't divisible by any of the primes in the array so far, pushes i onto the array
if(myArr.every((prime) => i % prime !==0)){
myArr.push(i)
}
console.log(myArr)
}
return myArr.reduce((initial,end) => initial + end,0)
}
console.log(sumPrimes(10));
If any of the primes in the list so far have a 0 remainder when i is divided by them, i is prime and does not belong in the list. It doesn’t get added.