JavaScript Implementation of Problem 10

View source code here on GitHub!

Includes

Problem Solution

p0010()

Project Euler Problem 10

Yet again, having a good prime number infrastructure comes in handy

Problem:

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

Find the sum of all the primes below two million.

Returns:

number --

 1/**
 2 * Project Euler Problem 10
 3 *
 4 * Yet again, having a good prime number infrastructure comes in handy
 5 *
 6 * Problem:
 7 *
 8 * The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
 9 *
10 * Find the sum of all the primes below two million.
11 *
12 * @return {number}
13 */
14exports.p0010 = function() {
15    let answer = 0;
16    for (const p of primes.primes(2000000)) {
17        answer += p;
18    }
19    return answer;
20};
21
22const primes = require('./lib/primes.js');

Tags: prime-number, js-iterator