From e4c46436e209843820d2486beae6fa8069c6301b Mon Sep 17 00:00:00 2001 From: Travis CI Date: Wed, 27 Dec 2017 10:04:52 +0000 Subject: [PATCH] Travis build: 358 --- README.md | 8 ++------ docs/index.html | 10 +++------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 56e348fe0..a29b99093 100644 --- a/README.md +++ b/README.md @@ -1337,17 +1337,13 @@ const arraySum = arr => arr.reduce((acc, val) => acc + val, 0); ### clampNumber -Clamps `num` within the inclusive `lower` and `upper` bounds. +Clamps `num` within the inclusive range specified by the boundary values `a` and `b` -If `lower` is greater than `upper`, swap them. If `num` falls within the range, return `num`. Otherwise, return the nearest number in the range. ```js -const clampNumber = (num, lower, upper) => { - if (lower > upper) upper = [lower, lower = upper][0]; - return (num >= lower && num <= upper) ? num : ((num < lower) ? lower : upper); -}; +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 diff --git a/docs/index.html b/docs/index.html index 2ef4632c4..64c55e5af 100644 --- a/docs/index.html +++ b/docs/index.html @@ -890,14 +890,10 @@ async function sleepyWork() { // arraySum([1,2,3,4]) -> 10

clampNumber

-

Clamps num within the inclusive lower and upper bounds.

-

If lower is greater than upper, swap them. -If num falls within the range, return num. +

Clamps num within the inclusive range specified by the boundary values a and b

+

If num falls within the range, return num. Otherwise, return the nearest number in the range.

-
const clampNumber = (num, lower, upper) => {
-  if (lower > upper) upper = [lower, lower = upper][0];
-  return (num >= lower && num <= upper) ? num : ((num < lower) ? lower : upper);
-};
+
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