Created
June 21, 2013 23:16
-
-
Save ursuleacv/5835023 to your computer and use it in GitHub Desktop.
Node js Prime function
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
prime = function (val) { | |
if (val === 1) return false; | |
else if (val === 2) return true; | |
else if (val !== undefined) { | |
var start = 1; | |
var valSqrt = Math.ceil(Math.sqrt(val)); | |
while (++start <= valSqrt) { | |
if (val % start === 0) { | |
return false; | |
} | |
} | |
return true; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment