Sum All Primes code example
Example: Sum All Primes
// I will update this code later, cause this is already very tasky,
// bad performance(Two loops inside a loop) // Very bad, but it works
const sumPrimes = num => {
const divisor = []
for(let i = 2; i <= num; i++){
let factorial = [], j = 1, num = []
while(j <= i){ factorial.push(j); j++ }
factorial.forEach(elem => {
if(i % elem === 0) num.push(elem)
})
if(num.length === 2) divisor.push(i)
}
return divisor.reduce((acc, cur) => acc + cur);
}
sumPrimes(977);