Travis build: 483
This commit is contained in:
76
README.md
76
README.md
@ -32,8 +32,6 @@
|
|||||||
<details>
|
<details>
|
||||||
<summary>View contents</summary>
|
<summary>View contents</summary>
|
||||||
|
|
||||||
* [`arrayGcd`](#arraygcd)
|
|
||||||
* [`arrayLcm`](#arraylcm)
|
|
||||||
* [`arrayMax`](#arraymax)
|
* [`arrayMax`](#arraymax)
|
||||||
* [`arrayMin`](#arraymin)
|
* [`arrayMin`](#arraymin)
|
||||||
* [`chunk`](#chunk)
|
* [`chunk`](#chunk)
|
||||||
@ -427,61 +425,6 @@ arrayMax([1, 2, 4]); // 4
|
|||||||
|
|
||||||
## Array
|
## Array
|
||||||
|
|
||||||
### arrayGcd
|
|
||||||
|
|
||||||
Calculates the greatest common denominator (gcd) of an array of numbers.
|
|
||||||
|
|
||||||
Use `Array.reduce()` and the `gcd` formula (uses recursion) to calculate the greatest common denominator of an array of numbers.
|
|
||||||
|
|
||||||
```js
|
|
||||||
const arrayGcd = arr => {
|
|
||||||
const gcd = (x, y) => (!y ? x : gcd(y, x % y));
|
|
||||||
return arr.reduce((a, b) => gcd(a, b));
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>Examples</summary>
|
|
||||||
|
|
||||||
```js
|
|
||||||
arrayGcd([1, 2, 3, 4, 5]); // 1
|
|
||||||
arrayGcd([4, 8, 12]); // 4
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
|
|
||||||
[⬆ Back to top](#table-of-contents)
|
|
||||||
|
|
||||||
|
|
||||||
### arrayLcm
|
|
||||||
|
|
||||||
Calculates the lowest common multiple (lcm) of an array of numbers.
|
|
||||||
|
|
||||||
Use `Array.reduce()` and the `lcm` formula (uses recursion) to calculate the lowest common multiple of an array of numbers.
|
|
||||||
|
|
||||||
```js
|
|
||||||
const arrayLcm = arr => {
|
|
||||||
const gcd = (x, y) => (!y ? x : gcd(y, x % y));
|
|
||||||
const lcm = (x, y) => x * y / gcd(x, y);
|
|
||||||
return arr.reduce((a, b) => lcm(a, b));
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>Examples</summary>
|
|
||||||
|
|
||||||
```js
|
|
||||||
arrayLcm([1, 2, 3, 4, 5]); // 60
|
|
||||||
arrayLcm([4, 8, 12]); // 24
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
|
|
||||||
[⬆ Back to top](#table-of-contents)
|
|
||||||
|
|
||||||
|
|
||||||
### arrayMax
|
### arrayMax
|
||||||
|
|
||||||
Returns the maximum value in an array.
|
Returns the maximum value in an array.
|
||||||
@ -2567,14 +2510,18 @@ fibonacciCountUntilNum(10); // 7
|
|||||||
|
|
||||||
### gcd
|
### gcd
|
||||||
|
|
||||||
Calculates the greatest common divisor between two numbers.
|
Calculates the greatest common divisor between two or more numbers/arrays.
|
||||||
|
|
||||||
Use recursion.
|
The `helperGcd `function uses recursion.
|
||||||
Base case is when `y` equals `0`. In this case, return `x`.
|
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`.
|
Otherwise, return the GCD of `y` and the remainder of the division `x/y`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const gcd = (x, y) => (!y ? x : gcd(y, 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));
|
||||||
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
@ -2750,15 +2697,17 @@ isPrime(12); // false
|
|||||||
|
|
||||||
### lcm
|
### lcm
|
||||||
|
|
||||||
Returns the least common multiple of two numbers.
|
Returns the least common multiple of two or numbers/arrays.
|
||||||
|
|
||||||
Use the greatest common divisor (GCD) formula and `Math.abs()` to determine the least common multiple.
|
Use the greatest common divisor (GCD) formula and `Math.abs()` to determine the least common multiple.
|
||||||
The GCD formula uses recursion.
|
The GCD formula uses recursion.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const lcm = (x, y) => {
|
const lcm = (...arr) => {
|
||||||
|
let data = [].concat(...arr);
|
||||||
const gcd = (x, y) => (!y ? x : gcd(y, x % y));
|
const gcd = (x, y) => (!y ? x : gcd(y, x % y));
|
||||||
return Math.abs(x * y) / gcd(x, y);
|
const helperLcm = (x, y) => x * y / gcd(x, y);
|
||||||
|
return arr.reduce((a, b) => helperLcm(a, b));
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -2767,6 +2716,7 @@ const lcm = (x, y) => {
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
lcm(12, 7); // 84
|
lcm(12, 7); // 84
|
||||||
|
lcm([1, 3, 4], 5); // 60
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|||||||
@ -107,9 +107,7 @@
|
|||||||
<a class="sublink-1" href="#spreadover">spreadOver</a>
|
<a class="sublink-1" href="#spreadover">spreadOver</a>
|
||||||
|
|
||||||
<h3>Array
|
<h3>Array
|
||||||
</h3><a class="sublink-1" href="#arraygcd">arrayGcd</a>
|
</h3><a class="sublink-1" href="#arraymax">arrayMax</a>
|
||||||
<a class="sublink-1" href="#arraylcm">arrayLcm</a>
|
|
||||||
<a class="sublink-1" href="#arraymax">arrayMax</a>
|
|
||||||
<a class="sublink-1" href="#arraymin">arrayMin</a>
|
<a class="sublink-1" href="#arraymin">arrayMin</a>
|
||||||
<a class="sublink-1" href="#chunk">chunk</a>
|
<a class="sublink-1" href="#chunk">chunk</a>
|
||||||
<a class="sublink-1" href="#compact">compact</a>
|
<a class="sublink-1" href="#compact">compact</a>
|
||||||
@ -342,30 +340,7 @@ arrayMax([1, 2, 3]); // 3
|
|||||||
arrayMax([1, 2, 4]); // 4
|
arrayMax([1, 2, 4]); // 4
|
||||||
</code></pre>
|
</code></pre>
|
||||||
</div></div><br/><h2 style="text-align:center">Array</h2>
|
</div></div><br/><h2 style="text-align:center">Array</h2>
|
||||||
<div class="card fluid"><div class="section double-padded"><h3 id="arraygcd">arrayGcd</h3></div><div class="section double-padded">
|
<div class="card fluid"><div class="section double-padded"><h3 id="arraymax">arrayMax</h3></div><div class="section double-padded">
|
||||||
<p>Calculates the greatest common denominator (gcd) of an array of numbers.</p>
|
|
||||||
<p>Use <code>Array.reduce()</code> and the <code>gcd</code> formula (uses recursion) to calculate the greatest common denominator of an array of numbers.</p>
|
|
||||||
<pre><code class="language-js">const arrayGcd = arr => {
|
|
||||||
const gcd = (x, y) => (!y ? x : gcd(y, x % y));
|
|
||||||
return arr.reduce((a, b) => gcd(a, b));
|
|
||||||
};
|
|
||||||
</code></pre>
|
|
||||||
<pre><code class="language-js">arrayGcd([1, 2, 3, 4, 5]); // 1
|
|
||||||
arrayGcd([4, 8, 12]); // 4
|
|
||||||
</code></pre>
|
|
||||||
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="arraylcm">arrayLcm</h3></div><div class="section double-padded">
|
|
||||||
<p>Calculates the lowest common multiple (lcm) of an array of numbers.</p>
|
|
||||||
<p>Use <code>Array.reduce()</code> and the <code>lcm</code> formula (uses recursion) to calculate the lowest common multiple of an array of numbers.</p>
|
|
||||||
<pre><code class="language-js">const arrayLcm = arr => {
|
|
||||||
const gcd = (x, y) => (!y ? x : gcd(y, x % y));
|
|
||||||
const lcm = (x, y) => x * y / gcd(x, y);
|
|
||||||
return arr.reduce((a, b) => lcm(a, b));
|
|
||||||
};
|
|
||||||
</code></pre>
|
|
||||||
<pre><code class="language-js">arrayLcm([1, 2, 3, 4, 5]); // 60
|
|
||||||
arrayLcm([4, 8, 12]); // 24
|
|
||||||
</code></pre>
|
|
||||||
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="arraymax">arrayMax</h3></div><div class="section double-padded">
|
|
||||||
<p>Returns the maximum value in an array.</p>
|
<p>Returns the maximum value in an array.</p>
|
||||||
<p>Use <code>Math.max()</code> combined with the spread operator (<code>...</code>) to get the maximum value in the array.</p>
|
<p>Use <code>Math.max()</code> combined with the spread operator (<code>...</code>) to get the maximum value in the array.</p>
|
||||||
<pre><code class="language-js">const arrayMax = arr => Math.max(...arr);
|
<pre><code class="language-js">const arrayMax = arr => Math.max(...arr);
|
||||||
@ -1170,11 +1145,15 @@ Uses a mathematical formula to calculate the length of the array required.</p>
|
|||||||
<pre><code class="language-js">fibonacciCountUntilNum(10); // 7
|
<pre><code class="language-js">fibonacciCountUntilNum(10); // 7
|
||||||
</code></pre>
|
</code></pre>
|
||||||
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="gcd">gcd</h3></div><div class="section double-padded">
|
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="gcd">gcd</h3></div><div class="section double-padded">
|
||||||
<p>Calculates the greatest common divisor between two numbers.</p>
|
<p>Calculates the greatest common divisor between two or more numbers/arrays.</p>
|
||||||
<p>Use recursion.
|
<p>The <code>helperGcd</code>function uses recursion.
|
||||||
Base case is when <code>y</code> equals <code>0</code>. In this case, return <code>x</code>.
|
Base case is when <code>y</code> equals <code>0</code>. In this case, return <code>x</code>.
|
||||||
Otherwise, return the GCD of <code>y</code> and the remainder of the division <code>x/y</code>.</p>
|
Otherwise, return the GCD of <code>y</code> and the remainder of the division <code>x/y</code>.</p>
|
||||||
<pre><code class="language-js">const gcd = (x, y) => (!y ? x : gcd(y, x % y));
|
<pre><code class="language-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));
|
||||||
|
};
|
||||||
</code></pre>
|
</code></pre>
|
||||||
<pre><code class="language-js">gcd(8, 36); // 4
|
<pre><code class="language-js">gcd(8, 36); // 4
|
||||||
</code></pre>
|
</code></pre>
|
||||||
@ -1241,15 +1220,18 @@ Return <code>false</code> if any of them divides the given number, else return <
|
|||||||
isPrime(12); // false
|
isPrime(12); // false
|
||||||
</code></pre>
|
</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 or numbers/arrays.</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.
|
||||||
The GCD formula uses recursion.</p>
|
The GCD formula uses recursion.</p>
|
||||||
<pre><code class="language-js">const lcm = (x, y) => {
|
<pre><code class="language-js">const lcm = (...arr) => {
|
||||||
|
let data = [].concat(...arr);
|
||||||
const gcd = (x, y) => (!y ? x : gcd(y, x % y));
|
const gcd = (x, y) => (!y ? x : gcd(y, x % y));
|
||||||
return Math.abs(x * y) / gcd(x, y);
|
const helperLcm = (x, y) => x * y / gcd(x, y);
|
||||||
|
return arr.reduce((a, b) => helperLcm(a, b));
|
||||||
};
|
};
|
||||||
</code></pre>
|
</code></pre>
|
||||||
<pre><code class="language-js">lcm(12, 7); // 84
|
<pre><code class="language-js">lcm(12, 7); // 84
|
||||||
|
lcm([1, 3, 4], 5); // 60
|
||||||
</code></pre>
|
</code></pre>
|
||||||
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="median">median</h3></div><div class="section double-padded">
|
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="median">median</h3></div><div class="section double-padded">
|
||||||
<p>Returns the median of an array of numbers.</p>
|
<p>Returns the median of an array of numbers.</p>
|
||||||
|
|||||||
@ -11,7 +11,7 @@ const gcd = (...arr) => {
|
|||||||
let data = [].concat(...arr);
|
let data = [].concat(...arr);
|
||||||
const helperGcd = (x, y) => (!y ? x : gcd(y, x % y));
|
const helperGcd = (x, y) => (!y ? x : gcd(y, x % y));
|
||||||
return data.reduce((a, b) => helperGcd(a, b));
|
return data.reduce((a, b) => helperGcd(a, b));
|
||||||
}
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
@ -10,11 +10,11 @@ const lcm = (...arr) => {
|
|||||||
let data = [].concat(...arr);
|
let data = [].concat(...arr);
|
||||||
const gcd = (x, y) => (!y ? x : gcd(y, x % y));
|
const gcd = (x, y) => (!y ? x : gcd(y, x % y));
|
||||||
const helperLcm = (x, y) => x * y / gcd(x, y);
|
const helperLcm = (x, y) => x * y / gcd(x, y);
|
||||||
return arr.reduce((a, b) => helperLcm(a, b))
|
return arr.reduce((a, b) => helperLcm(a, b));
|
||||||
}
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
lcm(12, 7); // 84
|
lcm(12, 7); // 84
|
||||||
lcm([1,3,4],5); // 60
|
lcm([1, 3, 4], 5); // 60
|
||||||
```
|
```
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
anagrams:string
|
anagrams:string
|
||||||
arrayAverage:math
|
arrayAverage:math
|
||||||
arrayGcd:array
|
|
||||||
arrayLcm:array
|
|
||||||
arrayMax:array
|
arrayMax:array
|
||||||
arrayMin:array
|
arrayMin:array
|
||||||
arraySum:math
|
arraySum:math
|
||||||
|
|||||||
Reference in New Issue
Block a user