Created
October 8, 2018 08:08
-
-
Save andreasvirkus/8d39d1bbb380d4eafbdeb91e46ca590f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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