minMax

Prev Next

Description

Checks the specified value and makes sure it is within the specified range. If less than the minimum, then the minimum is returned. If greater than the maximum, then the maximum is returned. Otherwise, the specified value is returned.


Input Parameters

Name Type Required Description
value Number Yes Value to check if within range
min Number Yes Minimum allowed value in range
max Number Yes Maximum allowed value in range

Returns

Type: Number

Checks if the passed value is within range and returns the appropriate value.


Examples

// checks to see if x is within the range of 10 to 20
// since true, 13 is returned
var x = 13;
x = tools.minMax(x, 10, 20);
JavaScript
// since false, 10 is returned
var x = 3;
x = tools.minMax(x, 10, 20);
JavaScript
// since false, 20 is returned
var x = 147;
x = tools.minMax(x, 10, 20);
JavaScript

Remarks

Use this helper function when you want to restrict a value within a certain range. This allows you to perform this restriction within a single line of code.