Skip to content

Instantly share code, notes, and snippets.

@nerdybeast
Created November 6, 2016 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nerdybeast/ff336518a8d875cce1a3c5661d9a0648 to your computer and use it in GitHub Desktop.
Save nerdybeast/ff336518a8d875cce1a3c5661d9a0648 to your computer and use it in GitHub Desktop.
Euler 7 - 10001'st Prime Number
'use strict';
const MAX = 10001;
let primes = [];
let n = 2;
while(primes.length < MAX) {
if(isPrime(n)) { primes.push(n); }
if(n === 2) { n++; } else { n += 2; }
}
function isPrime(n) {
let start = 2;
while(start <= Math.sqrt(n)) {
if(n % start++ === 0) return false;
}
return n > 1;
}
console.log('10001\'st prime number =>', primes.pop());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment