Nodejs Number Clamp clamp(min, max)

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

Method Source Code

'use strict';//ww  w .  j  a v a2 s  .co m
/**
 * Returns a number whose value is limited to the given range.
 *
 * Example: limit the output of this computation to between 0 and 255
 * (x * 255).clamp(0, 255)
 *
 * @param {Number} min The lower boundary of the output range
 * @param {Number} max The upper boundary of the output range
 * @returns A number in the range [min, max]
 * @type Number
 */
Number.prototype.clamp = function(min, max) {
  return Math.min(Math.max(this, min), max);
};

Related

  1. 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);
    
  2. 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);
    };
    
  3. clamp(min, max)
    Number.prototype.clamp = function(min, max) {
      return this < min ? min : (this > max ? max : this);
    };
    
  4. clamp(min, max)
    Number.prototype.clamp = function (min, max) {
      return this<min?min:this>max?max:this;
    };
    
  5. 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;
    ...
    
  6. clamp(min, max)
    Number.prototype.clamp = function(min, max) {
      return Math.min(Math.max(this, min), max);
    };
    
  7. clamp(min, max)
    Number.prototype.clamp = function(min, max) {
      return Math.min(Math.max(this, min), max);
    };
    
  8. clamp(min, max)
    window.rnd = function(p1, p2) {
            var r = Math.random();
            if (Array.isArray(p1)) {
                return p1[Math.floor(r * p1.length)];
            if (!(p1 === undefined)) {
                if (!(p2 === undefined)) {
                    r = r * (p2 - p1) + p1;
                } else {
    ...
    
  9. clamp(min, max)
    Number.prototype.clamp = function(min, max) {
      return Math.min(Math.max(this, min), max);
    };
    collides = function(a, b) {
        return a.x < b.x + b.width &&
          a.x + a.width > b.x &&
          a.y < b.y + b.height &&
          a.y + a.height > b.y;