19
README.md
19
README.md
@ -87,6 +87,7 @@
|
|||||||
* [`hammingDistance`](#hammingdistance)
|
* [`hammingDistance`](#hammingdistance)
|
||||||
* [`isDivisible`](#isdivisible)
|
* [`isDivisible`](#isdivisible)
|
||||||
* [`isEven`](#iseven)
|
* [`isEven`](#iseven)
|
||||||
|
* [`isPrime`](#isprime)
|
||||||
* [`lcm`](#lcm)
|
* [`lcm`](#lcm)
|
||||||
* [`median`](#median)
|
* [`median`](#median)
|
||||||
* [`palindrome`](#palindrome)
|
* [`palindrome`](#palindrome)
|
||||||
@ -1216,6 +1217,24 @@ const isEven = num => num % 2 === 0;
|
|||||||
|
|
||||||
[⬆ back to top](#table-of-contents)
|
[⬆ back to top](#table-of-contents)
|
||||||
|
|
||||||
|
### isPrime
|
||||||
|
|
||||||
|
Checks if the provided integer is a prime number.
|
||||||
|
|
||||||
|
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 => {
|
||||||
|
for (var i = 2; i < num; i++) if (num % i == 0) return false;
|
||||||
|
return num >= 2;
|
||||||
|
}
|
||||||
|
// isPrime(11) -> true
|
||||||
|
// isPrime(12) -> false
|
||||||
|
// isPrime(1) -> false
|
||||||
|
```
|
||||||
|
|
||||||
|
[⬆ back to top](#table-of-contents)
|
||||||
|
|
||||||
### lcm
|
### lcm
|
||||||
|
|
||||||
Returns the least common multiple of two numbers.
|
Returns the least common multiple of two numbers.
|
||||||
|
|||||||
@ -112,6 +112,7 @@
|
|||||||
<a class="sublink-1" href="#hammingdistance">hammingDistance</a>
|
<a class="sublink-1" href="#hammingdistance">hammingDistance</a>
|
||||||
<a class="sublink-1" href="#isdivisible">isDivisible</a>
|
<a class="sublink-1" href="#isdivisible">isDivisible</a>
|
||||||
<a class="sublink-1" href="#iseven">isEven</a>
|
<a class="sublink-1" href="#iseven">isEven</a>
|
||||||
|
<a class="sublink-1" href="#isprime">isPrime</a>
|
||||||
<a class="sublink-1" href="#lcm">lcm</a>
|
<a class="sublink-1" href="#lcm">lcm</a>
|
||||||
<a class="sublink-1" href="#median">median</a>
|
<a class="sublink-1" href="#median">median</a>
|
||||||
<a class="sublink-1" href="#palindrome">palindrome</a>
|
<a class="sublink-1" href="#palindrome">palindrome</a>
|
||||||
@ -761,6 +762,17 @@ Returns <code>true</code> if the number is even, <code>false</code> if the numbe
|
|||||||
<pre><code class="language-js">const isEven = num => num % 2 === 0;
|
<pre><code class="language-js">const isEven = num => num % 2 === 0;
|
||||||
// isEven(3) -> false
|
// isEven(3) -> false
|
||||||
</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">
|
||||||
|
<p>Checks if the provided integer is a prime number.</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 => {
|
||||||
|
for (var i = 2; i < num; i++) if (num % i == 0) return false;
|
||||||
|
return num >= 2;
|
||||||
|
}
|
||||||
|
// isPrime(11) -> true
|
||||||
|
// isPrime(12) -> false
|
||||||
|
// isPrime(1) -> false
|
||||||
|
</code></pre>
|
||||||
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="lcm">lcm</h3></div><div class="section double-padded">
|
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="lcm">lcm</h3></div><div class="section double-padded">
|
||||||
<p>Returns the least common multiple of two numbers.</p>
|
<p>Returns the least common multiple of two numbers.</p>
|
||||||
<p>Use the greatest common divisor (GCD) formula and <code>Math.abs()</code> to determine the least common multiple.
|
<p>Use the greatest common divisor (GCD) formula and <code>Math.abs()</code> to determine the least common multiple.
|
||||||
|
|||||||
15
snippets/isPrime.md
Normal file
15
snippets/isPrime.md
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
### isPrime
|
||||||
|
|
||||||
|
Checks if the provided integer is a prime number.
|
||||||
|
|
||||||
|
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 => {
|
||||||
|
for (var i = 2; i < num; i++) if (num % i == 0) return false;
|
||||||
|
return num >= 2;
|
||||||
|
}
|
||||||
|
// isPrime(11) -> true
|
||||||
|
// isPrime(12) -> false
|
||||||
|
// isPrime(1) -> false
|
||||||
|
```
|
||||||
@ -56,6 +56,7 @@ isDivisible:math
|
|||||||
isEven:math
|
isEven:math
|
||||||
isFunction:utility
|
isFunction:utility
|
||||||
isNumber:utility
|
isNumber:utility
|
||||||
|
isPrime:math
|
||||||
isString:utility
|
isString:utility
|
||||||
isSymbol:utility
|
isSymbol:utility
|
||||||
JSONToDate:date
|
JSONToDate:date
|
||||||
|
|||||||
Reference in New Issue
Block a user