Nodejs Number Value Map limit(min, max)

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

Method Source Code

Number.prototype.limit = function(min, max) {
    var i = this;
    if (i < min) i = min;
    if (i > max) i = max;
    return i;//from w  w  w. j  ava2s  . c  om
};

Related

  1. map(in_min, in_max, out_min, out_max)
    Number.prototype.map = function (in_min, in_max, out_min, out_max) {
      return (this - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
    Math.radians = function(degrees) {
      return degrees * Math.PI / 180;
    };
    
  2. map(in_min, in_max, out_min, out_max)
    Number.prototype.map = function (in_min, in_max, out_min, out_max) {
        return (this - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
    };
    
  3. map(in_min, in_max, out_min, out_max)
    Number.prototype.map = function (in_min, in_max, out_min, out_max) {
      return (this - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
    function convertToRange(value, srcRange, dstRange){
      if (value < srcRange[0] || value > srcRange[1]){
        return NaN; 
      var srcMax = srcRange[1] - srcRange[0],
        dstMax = dstRange[1] - dstRange[0],
    ...
    
  4. map(in_min, in_max, out_min, out_max)
    Number.prototype.map = function (in_min, in_max, out_min, out_max) {
        return (this - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
    
  5. map(istart, istop, ostart, ostop)
    Number.prototype.map = function (istart, istop, ostart, ostop) {
        return ostart + (ostop - ostart) * ((this - istart) / (istop - istart));
    };
    
  6. limit(min, max)
    Number.prototype.limit = function (min, max) {
        return Math.min(max, Math.max(min, this));
    };