I have a pretty hard time understanding what is going on in this FreeCodeCamp exercise code:
function sumPrimes(num) {
let primeNumbers = new Array;
for (let i = 2; i <= num; i++) {
if (primeNumbers.every(prime => i % prime !== 0)) {
primeNumbers.push(i);
}
}
return primeNumbers.reduce((sum, prime) => sum + prime);
}
console.log(sumPrimes(10));
Why does the every method here even work when the array (primeNumbers) is empty. And secondly how does the condition work with a parameter prime when there is nothing in the array from where does the function get the value for the parameter prime from?