This is a (pun intended) prime example of recursion allowing a more concise solution:
constsumPrime=(max,current=2,divisor=2,sum=0)=>// reached end of recursion, return sumcurrent>max?sum// found prime, add to sum and run with next value:current%divisor===0?sumPrime(max,current+1,2,sum+current)// value is is not a prime, run with next value:divisor>=current/2?sumPrime(max,current+1,2,sum)// otherwise increase divisor:sumPrime(max,current,divisor+1,sum);
Your solution is valid, just the use of an array to sum up the primes is superfluous.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This is a (pun intended) prime example of recursion allowing a more concise solution:
Your solution is valid, just the use of an array to sum up the primes is superfluous.