Javascript Math isPrime

Description

Javascript Math isPrime


Number.prototype.type = 'number';

Math.isPrime = function(n) {
 if(n==2) { return true; }
 if( (n < 2) || (n%2 == 0) ) { return false; }
 for(var i=3; (i*i)<=n; i+=2) {
  if(n%i == 0) { return false; }
 }
 return true;//from  w  w w .j a  v  a 2 s  . c o m
};

Math.isNumber = function isNumber(vtn) { //ref: http://stackoverflow.com/questions/9716468/is-there-any-function-like-isnumeric-in-javascript-to-validate-numbers
  return !isNaN(parseFloat(vtn)) && isFinite(vtn);
}



PreviousNext

Related