diff --git a/README.md b/README.md index 5354b4407..25490e54e 100644 --- a/README.md +++ b/README.md @@ -1381,13 +1381,11 @@ const isEven = num => num % 2 === 0; Checks if the provided integer is a prime number. -Check numbers from `2` to the square root of the given number. -Return `false` if any of them divides the given number, else return `true`, unless the number is less than `2`. +Returns `false` if the provided number has positive divisors other than 1 and itself or if the number itself is less than 2. ```js const isPrime = num => { - const boundary = Math.floor(Math.sqrt(num)); - for (var i = 2; i * i <= boundary; i++) if (num % i == 0) return false; + for (var i = 2; i * i <= num; i++) if (num % i == 0) return false; return num >= 2; }; // isPrime(11) -> true diff --git a/docs/index.html b/docs/index.html index 58e9617c8..2751272fd 100644 --- a/docs/index.html +++ b/docs/index.html @@ -866,11 +866,9 @@ Returns true if the number is even, false if the numbe

isPrime

Checks if the provided integer is a prime number.

-

Check numbers from 2 to the square root of the given number. -Return false if any of them divides the given number, else return true, unless the number is less than 2.

+

Returns false if the provided number has positive divisors other than 1 and itself or if the number itself is less than 2.

const isPrime = num => {
-  const boundary = Math.floor(Math.sqrt(num));
-  for (var i = 2; i * i <= boundary; i++) if (num % i == 0) return false;
+  for (var i = 2; i * i <= num; i++) if (num % i == 0) return false;
   return num >= 2;
 };
 // isPrime(11) -> true