Last active
November 4, 2018 18:09
-
-
Save OdearOgy/3d791d9426cd18cf58eb5eaf58927a81 to your computer and use it in GitHub Desktop.
this code logs sum of the prime nums in the given range
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const reducer = (accumulator, currentValue) => accumulator + currentValue; | |
| function somOfPrimes(range) { | |
| let store = []; | |
| let primes = []; | |
| for (let i = 2; i <= max; ++i) { | |
| if (!store [i]) { | |
| primes.push(i); | |
| for (let j = i << 1; j <= max; j += i) { | |
| store[j] = true; | |
| } | |
| } | |
| } | |
| return primes.reduce(reducer); | |
| } | |
| console.log(sumOfPrimes(100)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment