Skip to content

Instantly share code, notes, and snippets.

@gauravds
Created August 7, 2025 09:42
Show Gist options
  • Select an option

  • Save gauravds/728bda90943868079e4679e8751b3ffe to your computer and use it in GitHub Desktop.

Select an option

Save gauravds/728bda90943868079e4679e8751b3ffe to your computer and use it in GitHub Desktop.
Problem Nth Prime
// find the nth prime number,
// n = the indexes as 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,...
// prime number series as 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47...
// your program must return the nth Prime number as n = 5, then nth prime number is 11. return 11.
function nThPrime(n) {
//write your code here
let nThPrimeNumber = 2
return nThPrimeNumber
}
console.log(nThPrime(1), nThPrime(1) == 2) // 2, true
console.log(nThPrime(5), nThPrime(5) == 11) // 11, true
console.log(nThPrime(7), nThPrime(7) == 17) // 17, true
console.log(nThPrime(500), nThPrime(500) == 3571) // 3571, true
console.log(nThPrime(1000), nThPrime(1000) == 7919) // 7919, true
console.log(nThPrime(850), nThPrime(850) == 6571) // 6571, true
console.log(nThPrime(17), nThPrime(17) == 59) // 59, true
console.log(nThPrime(28), nThPrime(28) == 107) // 107, true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment