static isPrime(n) { let result; if (n <= 1) { result = false; } else { if (n == 2) { result = true; } else { if (n % 2 == 0) { result = false; } else { if (n <= 7) { result = true; } else { result = true let max = Math.sqrt(n) let factor = 3 while (factor <= max) { if (n % factor == 0) { result = false; } factor += 2; } } } } } return result; }
static isPrime(n) { // Special Cases if (n <= 1) return false; if (n == 2) return true; if (n % 2 == 0) return false; if (n <= 7) return true; let max = Math.sqrt(n) let factor = 3 // "Return" if we find result while (factor <= max) { if (n % factor == 0) return false; factor += 2; } return true; }
static isPrime(n) { let result; if (n <= 1) { result = false; } else { if (n == 2) { result = true; } else { if (n % 2 == 0) { result = false; } else { if (n <= 7) { result = true; } else { result = true let max = Math.sqrt(n) let factor = 3 while (factor <= max) { if (n % factor == 0) { result = false; } factor += 2; } } } } } return result; }
static isPrime(n) { // Special Cases if (n <= 1) return false; if (n == 2) return true; if (n % 2 == 0) return false; if (n <= 7) return true; let max = Math.sqrt(n) let factor = 3 // "Return" if we find result while (factor <= max) { if (n % factor == 0) return false; factor += 2; } return true; }