From 067cd4770df0ac9064ae21f72241a021f150f308 Mon Sep 17 00:00:00 2001 From: Gabriele Stefanini Date: Tue, 12 Dec 2017 11:50:06 +0100 Subject: [PATCH 1/3] add a isDivisible function --- README.md | 11 +++++++++++ snippets/divisible-by-number.md | 9 +++++++++ 2 files changed, 20 insertions(+) create mode 100644 snippets/divisible-by-number.md diff --git a/README.md b/README.md index bbadea755..f47dbd93a 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,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) @@ -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); ``` +### 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 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..46a5ac938 --- /dev/null +++ b/snippets/divisible-by-number.md @@ -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; +``` From bebc409972ddceecda95033cbf3b70ca056ddb3b Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Tue, 12 Dec 2017 16:31:39 +0200 Subject: [PATCH 2/3] Update divisible-by-number.md --- snippets/divisible-by-number.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/snippets/divisible-by-number.md b/snippets/divisible-by-number.md index 46a5ac938..7f608f12d 100644 --- a/snippets/divisible-by-number.md +++ b/snippets/divisible-by-number.md @@ -1,9 +1,7 @@ ### 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` +Use the modulo operator (`%`) to check if the remainder is equal to `0`. ```js -var isDivisible = (dividend, divisor) => dividend % divisor === 0; +const isDivisible = (dividend, divisor) => dividend % divisor === 0; ``` From 62beb227aa54a978089079624eba25e1e2a62bc8 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Tue, 12 Dec 2017 16:32:24 +0200 Subject: [PATCH 3/3] Update README.md --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f47dbd93a..278662766 100644 --- a/README.md +++ b/README.md @@ -128,12 +128,10 @@ 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` +Use the modulo operator (`%`) to check if the remainder is equal to `0`. ```js -var isDivisible = (dividend, divisor) => dividend % divisor === 0; +const isDivisible = (dividend, divisor) => dividend % divisor === 0; ``` ### Escape regular expression