re: Project Euler #7 - 10001st prime VIEW POST

FULL DISCUSSION
 

JS

function getPrimes(max) {
  let arr = new Array(max).fill(undefined);
  for (let i = 2; i < max; i++) {
    if (arr[i] === undefined) {
      arr[i] = true;
      for (let j = i + i; j < max; j += i) {
        arr[j] = false;
      }
    }
  }
  return arr
    .map((item, i) => item ? i : false)
    .filter(Boolean)
}

let primes = getPrimes(150000);
console.log(primes[10000]);
code of conduct - report abuse