Skip to content

Instantly share code, notes, and snippets.

@ursuleacv
Created June 21, 2013 23:16
Show Gist options
  • Save ursuleacv/5835023 to your computer and use it in GitHub Desktop.
Save ursuleacv/5835023 to your computer and use it in GitHub Desktop.
Node js Prime function
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