Function: clamp()
ts
function clamp(
value,
lower,
upper): number;Clamps a number within the inclusive lower and upper bounds. 将数字限制在指定的上下边界内。
Parameters
| Parameter | Type | Description |
|---|---|---|
value | number | The number to clamp / 要限制的数字 |
lower | number | The lower bound / 下边界 |
upper | number | The upper bound / 上边界 |
Returns
number
The clamped value / 限制后的值
Example
typescript
clamp(10, 0, 5) // => 5
clamp(-10, 0, 5) // => 0
clamp(3, 0, 5) // => 3Since
1.0.0