Filter syntax question

So I am doing the sum all primes algorithm, my question is, is it possible to add multiple tests in the filter method? and if so how?

function sumPrimes(num) {
  let potentialPrime = [];
  let i = num;
  while (i > 1) {
    potentialPrime.push(i);
    i--;
  }
  console.log(potentialPrime)
  const primeNumber = potentialPrime.filter((number) => {
    return number / number && number / 1;

  })
  console.log(primeNumber)
}


sumPrimes(10);

You can use filter then go for reduce.

What exactly are you hoping to do in this line? The filter method callback expects a return a truthy or falsy value. How will either side of the && happen?

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.