update snippets 1-15

This commit is contained in:
Stefan Feješ
2017-12-25 13:59:23 +01:00
committed by Agamemnon Zorbas
parent 9b8c9f4bcf
commit b2cffa6858
15 changed files with 72 additions and 31 deletions

View File

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