Travis build: 358
This commit is contained in:
@ -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) => {
|
||||
if (lower > upper) upper = [lower, lower = upper][0];
|
||||
return (num >= lower && num <= upper) ? num : ((num < lower) ? lower : upper);
|
||||
};
|
||||
<pre><code class="language-js">const clampNumber = (num, a, b) => Math.max(Math.min(num, Math.max(a,b)),Math.min(a,b));
|
||||
// clampNumber(2, 3, 5) -> 3
|
||||
// clampNumber(1, -1, -5) -> -1
|
||||
// clampNumber(3, 2, 4) -> 3
|
||||
|
||||
Reference in New Issue
Block a user