Travis build: 626

This commit is contained in:
Travis CI
2017-12-29 14:56:07 +00:00
parent 9f8b72fa64
commit 43ba1e0bcc
2 changed files with 6 additions and 8 deletions

View File

@ -2546,17 +2546,16 @@ isPrime(12); // false
### lcm
Returns the least common multiple of two or numbers/arrays.
Returns the least common multiple of two or more numbers/arrays.
Use the greatest common divisor (GCD) formula and `Math.abs()` to determine the least common multiple.
The GCD formula uses recursion.
```js
const lcm = (...arr) => {
let data = [].concat(...arr);
const gcd = (x, y) => (!y ? x : gcd(y, x % y));
const helperLcm = (x, y) => x * y / gcd(x, y);
return arr.reduce((a, b) => helperLcm(a, b));
const _lcm = (x, y) => x * y / gcd(x, y);
return [].concat(...arr).reduce((a, b) => _lcm(a, b));
};
```

View File

@ -482,11 +482,10 @@ isArmstrongNumber(56); // false
};
</code></pre><pre><code class="language-js">isPrime(11); // true
isPrime(12); // false
</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"><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. The GCD formula uses recursion.</p><pre><code class="language-js">const lcm = (...arr) =&gt; {
let data = [].concat(...arr);
</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"><p>Returns the least common multiple of two or more numbers/arrays.</p><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><pre><code class="language-js">const lcm = (...arr) =&gt; {
const gcd = (x, y) =&gt; (!y ? x : gcd(y, x % y));
const helperLcm = (x, y) =&gt; x * y / gcd(x, y);
return arr.reduce((a, b) =&gt; helperLcm(a, b));
const _lcm = (x, y) =&gt; x * y / gcd(x, y);
return [].concat(...arr).reduce((a, b) =&gt; _lcm(a, b));
};
</code></pre><pre><code class="language-js">lcm(12, 7); // 84
lcm([1, 3, 4], 5); // 60