Travis build: 358

This commit is contained in:
Travis CI
2017-12-27 10:04:52 +00:00
parent 0516737c4e
commit e4c46436e2
2 changed files with 5 additions and 13 deletions

View File

@ -890,14 +890,10 @@ async function sleepyWork() {
// arraySum([1,2,3,4]) -> 10
</code></pre>
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="clampnumber">clampNumber</h3></div><div class="section double-padded">
<p>Clamps <code>num</code> within the inclusive <code>lower</code> and <code>upper</code> bounds.</p>
<p>If <code>lower</code> is greater than <code>upper</code>, swap them.
If <code>num</code> falls within the range, return <code>num</code>.
<p>Clamps <code>num</code> within the inclusive range specified by the boundary values <code>a</code> and <code>b</code></p>
<p>If <code>num</code> falls within the range, return <code>num</code>.
Otherwise, return the nearest number in the range.</p>
<pre><code class="language-js">const clampNumber = (num, lower, upper) =&gt; {
if (lower &gt; upper) upper = [lower, lower = upper][0];
return (num &gt;= lower &amp;&amp; num &lt;= upper) ? num : ((num &lt; lower) ? lower : upper);
};
<pre><code class="language-js">const clampNumber = (num, a, b) =&gt; Math.max(Math.min(num, Math.max(a,b)),Math.min(a,b));
// clampNumber(2, 3, 5) -&gt; 3
// clampNumber(1, -1, -5) -&gt; -1
// clampNumber(3, 2, 4) -&gt; 3