Created
January 7, 2019 06:35
-
-
Save Trott/a85f99c5c5e18299f13a61616934b9d7 to your computer and use it in GitHub Desktop.
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
'use strict'; | |
const min = 2; | |
const max = 1e7; | |
const primes = []; | |
function generatePrimes(start, range) { | |
let isPrime = true; | |
let end = start + range; | |
for (let i = start; i < end; i++) { | |
for (let j = min; j < Math.sqrt(end); j++) { | |
if (i !== j && i%j === 0) { | |
isPrime = false; | |
break; | |
} | |
} | |
if (isPrime) { | |
primes.push(i); | |
} | |
isPrime = true; | |
} | |
} | |
generatePrimes(min, max); | |
console.log(primes.join('\n')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment