Travis build: 637

This commit is contained in:
30secondsofcode
2018-10-11 12:09:31 +00:00
parent 53fea89c85
commit 60e4d3895f
2 changed files with 2 additions and 2 deletions

View File

@ -2324,7 +2324,7 @@ remove([1, 2, 3, 4], n => n % 2 === 0); // [2, 4]
Returns a random element from an array.
Use `Math.random()` to generate a random number, multiply it by `length` and round it of to the nearest whole number using `Math.floor()`.
Use `Math.random()` to generate a random number, multiply it by `length` and round it off to the nearest whole number using `Math.floor()`.
This method also works with strings.
```js

View File

@ -412,7 +412,7 @@
}, [])
: [];</span>
</pre><label class="collapse">examples</label><pre class="section card-examples language-js"><span class="token function">remove</span><span class="token punctuation">([</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">],</span> n <span class="token operator">=></span> n <span class="token operator">%</span> <span class="token number">2</span> <span class="token operator">===</span> <span class="token number">0</span><span class="token punctuation">);</span> <span class="token comment">// [2, 4]</span>
</pre></div><div class="card code-card"><div class="corner beginner"></div><div class="section card-content"><h4 id="sample">sample</h4><p>Returns a random element from an array.</p><p>Use <code>Math.random()</code> to generate a random number, multiply it by <code>length</code> and round it of to the nearest whole number using <code>Math.floor()</code>. This method also works with strings.</p></div><div class="copy-button-container"><button class="copy-button" aria-label="Copy to clipboard"></button></div><pre class="section card-code language-js"><span class="token keyword">const</span> <span class="token function-variable function">sample</span> <span class="token operator">=</span> arr <span class="token operator">=></span> arr<span class="token punctuation">[</span>Math<span class="token punctuation">.</span><span class="token function">floor</span><span class="token punctuation">(</span>Math<span class="token punctuation">.</span><span class="token function">random</span><span class="token punctuation">()</span> <span class="token operator">*</span> arr<span class="token punctuation">.</span>length<span class="token punctuation">)];</span>
</pre></div><div class="card code-card"><div class="corner beginner"></div><div class="section card-content"><h4 id="sample">sample</h4><p>Returns a random element from an array.</p><p>Use <code>Math.random()</code> to generate a random number, multiply it by <code>length</code> and round it off to the nearest whole number using <code>Math.floor()</code>. This method also works with strings.</p></div><div class="copy-button-container"><button class="copy-button" aria-label="Copy to clipboard"></button></div><pre class="section card-code language-js"><span class="token keyword">const</span> <span class="token function-variable function">sample</span> <span class="token operator">=</span> arr <span class="token operator">=></span> arr<span class="token punctuation">[</span>Math<span class="token punctuation">.</span><span class="token function">floor</span><span class="token punctuation">(</span>Math<span class="token punctuation">.</span><span class="token function">random</span><span class="token punctuation">()</span> <span class="token operator">*</span> arr<span class="token punctuation">.</span>length<span class="token punctuation">)];</span>
</pre><label class="collapse">examples</label><pre class="section card-examples language-js"><span class="token function">sample</span><span class="token punctuation">([</span><span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">7</span><span class="token punctuation">,</span> <span class="token number">9</span><span class="token punctuation">,</span> <span class="token number">11</span><span class="token punctuation">]);</span> <span class="token comment">// 9</span>
</pre></div><div class="card code-card"><div class="corner intermediate"></div><div class="section card-content"><h4 id="samplesize">sampleSize</h4><p>Gets <code>n</code> random elements at unique keys from <code>array</code> up to the size of <code>array</code>.</p><p>Shuffle the array using the <a href="https://github.com/30-seconds/30-seconds-of-code#shuffle">Fisher-Yates algorithm</a>. Use <code>Array.prototype.slice()</code> to get the first <code>n</code> elements. Omit the second argument, <code>n</code> to get only one element at random from the array.</p></div><div class="copy-button-container"><button class="copy-button" aria-label="Copy to clipboard"></button></div><pre class="section card-code language-js"><span class="token keyword">const</span> <span class="token function-variable function">sampleSize</span> <span class="token operator">=</span> <span class="token punctuation">([</span><span class="token operator">...</span>arr<span class="token punctuation">],</span> n <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span>
<span class="token keyword">let</span> m <span class="token operator">=</span> arr<span class="token punctuation">.</span>length<span class="token punctuation">;</span>