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
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