Travis build: 93
This commit is contained in:
@ -1381,13 +1381,11 @@ const isEven = num => num % 2 === 0;
|
|||||||
|
|
||||||
Checks if the provided integer is a prime number.
|
Checks if the provided integer is a prime number.
|
||||||
|
|
||||||
Check numbers from `2` to the square root of the given number.
|
Returns `false` if the provided number has positive divisors other than 1 and itself or if the number itself is less than 2.
|
||||||
Return `false` if any of them divides the given number, else return `true`, unless the number is less than `2`.
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const isPrime = num => {
|
const isPrime = num => {
|
||||||
const boundary = Math.floor(Math.sqrt(num));
|
for (var i = 2; i * i <= num; i++) if (num % i == 0) return false;
|
||||||
for (var i = 2; i * i <= boundary; i++) if (num % i == 0) return false;
|
|
||||||
return num >= 2;
|
return num >= 2;
|
||||||
};
|
};
|
||||||
// isPrime(11) -> true
|
// isPrime(11) -> true
|
||||||
|
|||||||
@ -866,11 +866,9 @@ Returns <code>true</code> if the number is even, <code>false</code> if the numbe
|
|||||||
</code></pre>
|
</code></pre>
|
||||||
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="isprime">isPrime</h3></div><div class="section double-padded">
|
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="isprime">isPrime</h3></div><div class="section double-padded">
|
||||||
<p>Checks if the provided integer is a prime number.</p>
|
<p>Checks if the provided integer is a prime number.</p>
|
||||||
<p>Check numbers from <code>2</code> to the square root of the given number.
|
<p>Returns <code>false</code> if the provided number has positive divisors other than 1 and itself or if the number itself is less than 2.</p>
|
||||||
Return <code>false</code> if any of them divides the given number, else return <code>true</code>, unless the number is less than <code>2</code>.</p>
|
|
||||||
<pre><code class="language-js">const isPrime = num => {
|
<pre><code class="language-js">const isPrime = num => {
|
||||||
const boundary = Math.floor(Math.sqrt(num));
|
for (var i = 2; i * i <= num; i++) if (num % i == 0) return false;
|
||||||
for (var i = 2; i * i <= boundary; i++) if (num % i == 0) return false;
|
|
||||||
return num >= 2;
|
return num >= 2;
|
||||||
};
|
};
|
||||||
// isPrime(11) -> true
|
// isPrime(11) -> true
|
||||||
|
|||||||
Reference in New Issue
Block a user