Travis build: 93

This commit is contained in:
Pl4gue
2017-12-22 08:36:56 +00:00
parent 8570cd09ad
commit 3db8491741
2 changed files with 4 additions and 8 deletions

View File

@ -866,11 +866,9 @@ Returns <code>true</code> if the number is even, <code>false</code> if the numbe
</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">
<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.
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>
<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>
<pre><code class="language-js">const isPrime = num =&gt; {
const boundary = Math.floor(Math.sqrt(num));
for (var i = 2; i * i &lt;= boundary; i++) if (num % i == 0) return false;
for (var i = 2; i * i &lt;= num; i++) if (num % i == 0) return false;
return num &gt;= 2;
};
// isPrime(11) -&gt; true