add a isDivisible function
This commit is contained in:
11
README.md
11
README.md
@ -16,6 +16,7 @@
|
|||||||
* [Curry](#curry)
|
* [Curry](#curry)
|
||||||
* [Difference between arrays](#difference-between-arrays)
|
* [Difference between arrays](#difference-between-arrays)
|
||||||
* [Distance between two points](#distance-between-two-points)
|
* [Distance between two points](#distance-between-two-points)
|
||||||
|
* [Divisible by number](#divisible-by-number)
|
||||||
* [Escape regular expression](#escape-regular-expression)
|
* [Escape regular expression](#escape-regular-expression)
|
||||||
* [Even or odd number](#even-or-odd-number)
|
* [Even or odd number](#even-or-odd-number)
|
||||||
* [Factorial](#factorial)
|
* [Factorial](#factorial)
|
||||||
@ -125,6 +126,16 @@ Use `Math.hypot()` to calculate the Euclidean distance between two points.
|
|||||||
const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
|
const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Divisible by number
|
||||||
|
|
||||||
|
Using the module operator `%` we can check if the reminder is equal
|
||||||
|
to zero. In this case the function returns `true`. We can use this
|
||||||
|
function for checking if a number is even or odd passing 2 as `divisor`
|
||||||
|
|
||||||
|
```js
|
||||||
|
var isDivisible = (dividend, divisor) => dividend % divisor === 0;
|
||||||
|
```
|
||||||
|
|
||||||
### Escape regular expression
|
### Escape regular expression
|
||||||
|
|
||||||
Use `replace()` to escape special characters.
|
Use `replace()` to escape special characters.
|
||||||
|
|||||||
9
snippets/divisible-by-number.md
Normal file
9
snippets/divisible-by-number.md
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
### Divisible by number
|
||||||
|
|
||||||
|
Using the module operator `%` we can check if the reminder is equal
|
||||||
|
to zero. In this case the function returns `true`. We can use this
|
||||||
|
function for checking if a number is even or odd passing 2 as `divisor`
|
||||||
|
|
||||||
|
```js
|
||||||
|
var isDivisible = (dividend, divisor) => dividend % divisor === 0;
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user