update snippets 1-15
This commit is contained in:
committed by
Agamemnon Zorbas
parent
9b8c9f4bcf
commit
b2cffa6858
@ -1,13 +1,16 @@
|
||||
### clampNumber
|
||||
|
||||
Clamps `num` within the inclusive range specified by the boundary values `a` and `b`
|
||||
Clamps `num` within the inclusive range specified by the boundary values `a` and `b`.
|
||||
|
||||
If `num` falls within the range, return `num`.
|
||||
If `num` falls within the range, return `num`.
|
||||
Otherwise, return the nearest number in the range.
|
||||
|
||||
```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
|
||||
```
|
||||
|
||||
```js
|
||||
clampNumber(2, 3, 5) // 3
|
||||
clampNumber(1, -1, -5) // -1
|
||||
clampNumber(3, 2, 4) // 3
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user