Skip to content

Instantly share code, notes, and snippets.

@andreasvirkus
Created October 8, 2018 08:08
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 andreasvirkus/8d39d1bbb380d4eafbdeb91e46ca590f to your computer and use it in GitHub Desktop.
Save andreasvirkus/8d39d1bbb380d4eafbdeb91e46ca590f to your computer and use it in GitHub Desktop.
function isPrimeNumber(n) {
for (var i = 2; i < n; i++) { // i will always be less than the parameter so the condition below will never allow parameter to be divisible by itself ex. (7 % 7 = 0) which would return true
if (n % i === 0) return false // when parameter is divisible by i, it's not a prime number so return false
}
return n > 1 // otherwise it's a prime number so return true (it also must be greater than 1, reason for the n > 1 instead of true)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment