Hello

I’ve been stuck on Sum All Primes for ages, probably spent a good 4 hours trying different solutions.

I thought I was getting somewhere using filter, though it seems to be going wrong, as I get a console error of “Reduce of empty array with no initial value” so for some reason I assume this means the filter isn’t working.

Can anyone point me in the correct direction of what I am doing wrong? I’m not looking for the answer per se, just want to know what I am doing wrong…or if I am barking up the wrong tree completely.

Code below - thanks, James

function sumPrimes(num) {

var array = [];

for (var i=2; i<=num; i++) {

array.push(i);

}

array.filter(function() {

for (var j=0; j<=array.length; j++) {

if (num % array[j] === 0) {

return false;

```
}
return true;
}
```

}).reduce(function(a,b) {

return a + b;

});

}

sumPrimes(10);