From dbf91b100956a553dd189531c41a0df682c8f94b Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Thu, 4 Jan 2018 14:18:59 +0000 Subject: [PATCH] Travis build: 1030 --- README.md | 7 +++---- docs/index.html | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 60bfdc344..eb88d68c1 100644 --- a/README.md +++ b/README.md @@ -3039,15 +3039,14 @@ fibonacciUntilNum(10); // [ 0, 1, 1, 2, 3, 5, 8 ] Calculates the greatest common divisor between two or more numbers/arrays. -The `helperGcd `function uses recursion. +The inner `_gcd` function uses recursion. Base case is when `y` equals `0`. In this case, return `x`. Otherwise, return the GCD of `y` and the remainder of the division `x/y`. ```js const gcd = (...arr) => { - let data = [].concat(...arr); - const helperGcd = (x, y) => (!y ? x : gcd(y, x % y)); - return data.reduce((a, b) => helperGcd(a, b)); + const _gcd = (x, y) => (!y ? x : gcd(y, x % y)); + return [].concat(...arr).reduce((a, b) => _gcd(a, b)); }; ``` diff --git a/docs/index.html b/docs/index.html index b63e3cf33..b186768df 100644 --- a/docs/index.html +++ b/docs/index.html @@ -644,10 +644,9 @@ own individual rating by supplying it as the third argument. ); };
fibonacciUntilNum(10); // [ 0, 1, 1, 2, 3, 5, 8 ]
-

gcd

Calculates the greatest common divisor between two or more numbers/arrays.

The helperGcdfunction uses recursion. Base case is when y equals 0. In this case, return x. Otherwise, return the GCD of y and the remainder of the division x/y.

const gcd = (...arr) => {
-  let data = [].concat(...arr);
-  const helperGcd = (x, y) => (!y ? x : gcd(y, x % y));
-  return data.reduce((a, b) => helperGcd(a, b));
+

gcd

Calculates the greatest common divisor between two or more numbers/arrays.

The inner _gcd function uses recursion. Base case is when y equals 0. In this case, return x. Otherwise, return the GCD of y and the remainder of the division x/y.

const gcd = (...arr) => {
+  const _gcd = (x, y) => (!y ? x : gcd(y, x % y));
+  return [].concat(...arr).reduce((a, b) => _gcd(a, b));
 };
 
gcd(8, 36); // 4
 

geometricProgression

Initializes an array containing the numbers in the specified range where start and end are inclusive and the ratio between two terms is step. Returns an error if step equals 1.

Use Array.from(), Math.log() and Math.floor() to create an array of the desired length, Array.map() to fill with the desired values in a range. Omit the second argument, start, to use a default value of 1. Omit the third argument, step, to use a default value of 2.

const geometricProgression = (end, start = 1, step = 2) =>