Nodejs Number Clamp clamp(a, min, max)

Here you can find the source of clamp(a, min, max)

Method Source Code

Math.clamp = function(a, min, max) {
    return a < min ? min : (a > max ? max : a);
};

Related

  1. clamp(val, min, max)
    Math.clamp = function(val, min, max) {
      return Math.min(Math.max(val, min), max);
    };
    
  2. clamp( min, max )
    Number.prototype.clamp = function( min, max ) 
      return Math.min( Math.max( this, min ), max );
    };
    
  3. clamp(min, max)
    Number.prototype.clamp = function(min, max) {
      if (this < min) return min;
      if (max < this) return max;
      return this.valueOf();
    };
    
  4. clamp(min, max)
    Number.prototype.clamp = function(min, max) {
      return Math.max(min, Math.min(this, max));
    };