Nodejs Number Clamp clamp(min, max)

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

Method Source Code

/**/*from   w  ww  .ja va  2s.  c o  m*/
 *  Number#clamp(min, max) -> Number
 *  - min (Number): The minimum allowable value.
 *  - max (Number): The maximum allowable value.
 *
 *  Returns the `min` or `max` value if the number is outside the specified range.
**/
Number.prototype.clamp = function(min, max) {
  // Via http://twitter.com/kangax/status/13023629344
  return this < min ? min : (this > max ? max : this);
};

Related

  1. clamp(min, max)
    Number.prototype.clamp = function(min, max) {
      return Math.max(min, Math.min(this, max));
    };
    
  2. clamp(min, max)
    Number.prototype.clamp = function(min, max) {
      return Math.min(Math.max(this, min), max);
    };
    
  3. clamp(min, max)
    "use strict";
    var _this = this;
    Number.prototype.clamp = function (min, max) { 
      return Math.min(Math.max(_this, max), min); 
    };
    
  4. 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);
    
  5. 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);
    };
    
  6. clamp(min, max)
    Number.prototype.clamp = function (min, max) {
      return this<min?min:this>max?max:this;
    };
    
  7. clamp(min, max)
    Number.prototype.clamp = function(min, max) {
      return Math.min(Math.max(this, min), max);
    };
    function calcAngle(x1, x2, y1, y2) {
      var calcAngle = Math.atan2(x1-x2,y1-y2)*(180/Math.PI);
      if(calcAngle < 0)
        calcAngle = Math.abs(calcAngle);
      else
        calcAngle = 360 - calcAngle;
    ...
    
  8. clamp(min, max)
    'use strict';
    Number.prototype.clamp = function(min, max) {
      return Math.min(Math.max(this, min), max);
    };
    
  9. clamp(min, max)
    Number.prototype.clamp = function(min, max) {
      return Math.min(Math.max(this, min), max);
    };