Created
April 27, 2022 18:38
-
-
Save MuddyBootsCode/e0e1941f901880837aa74580a1c3b42d to your computer and use it in GitHub Desktop.
This file contains 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
function nthPrime(n) { | |
let count = 0; | |
let current = 2; | |
let prime = 2; | |
while(count < n){ | |
let isPrime = true; | |
for(let i = 2; i < current; i++){ | |
if(current % i === 0){ | |
isPrime = false; | |
break; | |
} | |
} | |
if(isPrime){ | |
prime = current; | |
count += 1; | |
} | |
if(current === 2){ | |
current = 3; | |
} else { | |
current += 2; | |
} | |
} | |
return prime; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment