Hi, I’m trying to solve “Sum All Primes” challenge. I decided to use Sieve of Eratosthenes as part of my solution. Here is the Wikipedia article about this method.
I’m not asking if my implementation is good, if it isn’t I’ll figure it out myself. Question is why I’m getting “TypeError: acc.push is not a function” message, when acc is passed as empty array.
Code:
function sieveOfE(arr, acc) {
if (arr === []) {
return acc;
}
return sieveOfE(arr.slice(1)
.filter(function (e) {
return e % arr[0] !== 0;
}),
acc.push(arr[0]));
}
console.log([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], []));
Thanx in advance.