Nodejs Number Clamp clamp(min, max)

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

Method Source Code

"use strict";//from   ww  w. j  a  va 2  s  .co m

var _this = this;
Number.prototype.clamp = function (min, max) { 
   return Math.min(Math.max(_this, max), min); 
};

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));
    };
    
  5. clamp(min, max)
    Number.prototype.clamp = function(min, max) {
      return Math.min(Math.max(this, min), max);
    };
    
  6. clamp(min, max)
    Number.prototype.clamp = function (min, max) {
      return Math.min(Math.max(this, min), max);
    };
    function randomFloat(min, max) {
      return min + Math.random() * (max - min);
    
  7. clamp(min, max)
    window.addEventListener("keydown", function(e) {
      if([32, 37, 38, 39, 40].indexOf(e.keyCode) > -1) {
        e.preventDefault();
    }, false);
    Number.prototype.clamp = function(min, max) {
      return Math.min(Math.max(this, min), max);
    };
    
  8. clamp(min, max)
    Number.prototype.clamp = function(min, max) {
      return this < min ? min : (this > max ? max : this);
    };
    
  9. clamp(min, max)
    Number.prototype.clamp = function (min, max) {
      return this<min?min:this>max?max:this;
    };