Ad
Mathematics
Algorithms
Logic
Numbers

Optimized

Code
Diff
  • function prime_checker (n) {
      if ([0,1].includes(n)) return false;
      if (n == 2) return true;
      if (n % 2 == 0) return false;
      for(let i = 3; i < Math.sqrt(n); i += 2) {
        if(n % i === 0) return false;
      }
      return true;  
    }
    • function prime_checker (n) {
    • if ([0,1].includes(n)) return false;
    • if (n == 2) return true;
    • if (n % 2 == 0) return false;
    • for(let i = 3; i < n; i += 2) {
    • for(let i = 3; i < Math.sqrt(n); i += 2) {
    • if(n % i === 0) return false;
    • }
    • return true;
    • }