Travis build: 254

This commit is contained in:
Travis CI
2017-12-24 21:20:03 +00:00
parent 2ebb86f629
commit 4cf66fd758
2 changed files with 4 additions and 12 deletions

View File

@ -2302,14 +2302,10 @@ const isSymbol = val => typeof val === 'symbol';
Generates a random hexadecimal color code. Generates a random hexadecimal color code.
Use `Math.random` to generate a random number and limit that number to fall in between 0 and 16 using `Math.floor`. Use the generated random number as index to access a character from 0 to F. Append it to `color` till the length is not `7`. Use `Math.random` to generate a random 24-bit(6x4bits) hexadecimal number. Use bit shifting and then convert it to an hexadecimal String using `toString(16)`.
```js ```js
const randomHexColorCode = () => { const randomHexColorCode = () => '#'+(Math.random()*0xFFFFFF<<0).toString(16);
let color = '#';
while(color.length < 7) color += '0123456789ABCDEF'[Math.floor(Math.random() * 16)];
return color;
}
// randomHexColorCode() -> "#e34155" // randomHexColorCode() -> "#e34155"
// randomHexColorCode() -> "#fd73a6" // randomHexColorCode() -> "#fd73a6"
// randomHexColorCode() -> "#4144c6" // randomHexColorCode() -> "#4144c6"

View File

@ -1440,12 +1440,8 @@ Omit the second argument to use the default regex.</p>
</code></pre> </code></pre>
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="randomhexcolorcode">randomHexColorCode</h3></div><div class="section double-padded"> </div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="randomhexcolorcode">randomHexColorCode</h3></div><div class="section double-padded">
<p>Generates a random hexadecimal color code.</p> <p>Generates a random hexadecimal color code.</p>
<p>Use <code>Math.random</code> to generate a random number and limit that number to fall in between 0 and 16 using <code>Math.floor</code>. Use the generated random number as index to access a character from 0 to F. Append it to <code>color</code> till the length is not <code>7</code>.</p> <p>Use <code>Math.random</code> to generate a random 24-bit(6x4bits) hexadecimal number. Use bit shifting and then convert it to an hexadecimal String using <code>toString(16)</code>.</p>
<pre><code class="language-js">const randomHexColorCode = () =&gt; { <pre><code class="language-js">const randomHexColorCode = () =&gt; '#'+(Math.random()*0xFFFFFF&lt;&lt;0).toString(16);
let color = '#';
while(color.length &lt; 7) color += '0123456789ABCDEF'[Math.floor(Math.random() * 16)];
return color;
}
// randomHexColorCode() -&gt; &quot;#e34155&quot; // randomHexColorCode() -&gt; &quot;#e34155&quot;
// randomHexColorCode() -&gt; &quot;#fd73a6&quot; // randomHexColorCode() -&gt; &quot;#fd73a6&quot;
// randomHexColorCode() -&gt; &quot;#4144c6&quot; // randomHexColorCode() -&gt; &quot;#4144c6&quot;