I am writing code to find the sum of all primes below a given number (in this case I want to find it for 2000000)
My code will run just fine for numbers like 20000 and lower, but as I add 0s to it, it won't.
I tried to run it on codesandbox and it'll tell me there's a potential infinite loop somewhere.
const isPrime = number => {
let k=0
for (let i=2; i < number; i++) {
if (number % i === 0) {
k++
}
}
if (k === 0) {
return true
} else {
return false
}
}
const sumOfPrimes = limit => {
let primeSum = 0
for (let i=1; i <= limit; i++) {
if (isPrime(i)) {
primeSum += i
}
} console.log(primeSum);
}
sumOfPrimes(2000000);