clamp source npm

_.clamp(number, [min], max)

Returns a number whose value is limited to the given range specified by min and max.

Arguments

  1. number (number)

    The number whose value is to be limited.

  2. [min] (number)

    The minimum possible value.

  3. max (number)

    The maximum possible value.

Returns (number)

A number in the range [min, max].

Example

_.clamp(-10, -5, 5);
// => -5

_.clamp(10, -5, 5);
// => 5