diff --git a/README.md b/README.md index 634895806..dee253d4a 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ * [Curry](#curry) * [Difference between arrays](#difference-between-arrays) * [Distance between two points](#distance-between-two-points) +* [Divisible by number](#divisible-by-number) * [Escape regular expression](#escape-regular-expression) * [Even or odd number](#even-or-odd-number) * [Factorial](#factorial) @@ -147,6 +148,14 @@ Use `Math.hypot()` to calculate the Euclidean distance between two points. const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0); ``` +### Divisible by number + +Use the modulo operator (`%`) to check if the remainder is equal to `0`. + +```js +const isDivisible = (dividend, divisor) => dividend % divisor === 0; +``` + ### Escape regular expression Use `replace()` to escape special characters. diff --git a/snippets/divisible-by-number.md b/snippets/divisible-by-number.md new file mode 100644 index 000000000..7f608f12d --- /dev/null +++ b/snippets/divisible-by-number.md @@ -0,0 +1,7 @@ +### Divisible by number + +Use the modulo operator (`%`) to check if the remainder is equal to `0`. + +```js +const isDivisible = (dividend, divisor) => dividend % divisor === 0; +```