function clamp(value, minValue, maxValue) {
  if (minValue > maxValue) {
    [minValue, maxValue] = [maxValue, minValue];
  }

  return max(minValue, min(value, maxValue));
}
Clamp value
@param {number} value - Value
@param {number} minValue - Minimum value
@param {number} maxValue - Maximum value
@returns {number} clamped value