Project Euler Problems 1 to 100 - Problem 10: Summation of primes

Tell us what’s happening:
Describe your issue in detail here.
code is failing only for the case 2000000
Your code so far

function primeSummation(n) {
  let numList=[2];
  let validation=true
  let num=2;
  while (validation==true)
  {
    num=num+1
    if (isPrime(num,numList)==true &&num<n)
    {
      numList.push(num)
    }
    if (num>=n)
    {
      validation=false
    }
  }
  console.log(
  numList.reduce((a, b) => a + b, 0)
)
  return (
  numList.reduce((a, b) => a + b, 0)
)
  // let sum=0
  // for (let i=0;i<numList.length)
  // return true;
}

function isPrime(num,list)
{
  let count=0
    for (let i=0;i<list.length;i++)
    {
      if (num%list[i]==0)
      {
        count=count+1;
        break;
      }
    }
    if (count>0)
    {
      return false
    }
    else
    {
      return true
    }
}

primeSummation(2000000);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Safari/605.1.15

Challenge: Project Euler Problems 1 to 100 - Problem 10: Summation of primes

Link to the challenge:

This is an indication that your solution code isn’t fast enough. Project Euler is about efficient solutions.

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