sum of all primes below 2 javascript

Solutions on MaxInterview for sum of all primes below 2 javascript by the best coders in the world

showing results for - "sum of all primes below 2 javascript"
Jonah
26 Aug 2016
1
2function sumPrimes(num) {
3
4    let sum = 0;
5
6    const isPrime = n => {
7        for (let i = 2; i < n; i++)
8            if (n % i === 0) return false;
9        return n !== 1;
10    }
11
12    for (i = 2; i <= num; i++) {
13        if (isPrime(i)) {
14            sum += i;
15            console.log(i);
16            console.log(isPrime(i));
17        }
18    }
19
20    console.log(sum);
21    return sum;
22}
23
24// test here
25sumPrimes(10);
26