Answers for "sum of all primes below 2 javascript"

0

sum of all primes below 2 javascript

function sumPrimes(num) {

    let sum = 0;

    const isPrime = n => {
        for (let i = 2; i < n; i++)
            if (n % i === 0) return false;
        return n !== 1;
    }

    for (i = 2; i <= num; i++) {
        if (isPrime(i)) {
            sum += i;
            console.log(i);
            console.log(isPrime(i));
        }
    }

    console.log(sum);
    return sum;
}

// test here
sumPrimes(10);
Posted by: Guest on April-07-2021

Code answers related to "sum of all primes below 2 javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language