function isPrime(number) { if (typeof number !== ‘number‘) { // 不是数字 return false; } if (number < 2) { return false; } if (number === 2) { return true; } else if (number % 2 === 0) { return false; } var squareRoot = Math.sqrt(number); for(var i = 3; i <= squareRoot; i += 2) { if (number % i === 0) { return false; } } return true; }
时间: 2024-09-28 07:17:43