Nodejs Number Calculate range(a, b, i)

Here you can find the source of range(a, b, i)

Method Source Code

/**/*  www.j a v  a2 s .c  om*/
 * Extend Number with range, to find
 * if a given number falls within range
 * 
 * @param  a [min]
 * @param  b [max]
 * @param  i [inclusive: boolean]
 * @return {Boolean}
 */
Number.prototype.range  = function (a, b, i) {
    i = i || true;
    var min = Math.min.apply(Math, [a, b]),
        max = Math.max.apply(Math, [a, b]);
    return i ? this >= min && this <= max : this > min && this < max;
};

Related

  1. plural(a, b, c)
    Number.prototype.plural = function (a, b, c)
      if (this % 1)
        return b
      var v = Math.abs(this) % 100
      if (11 <= v && v <= 19)
        return c
      v = v % 10
      if (2 <= v && v <= 4)
    ...
    
  2. pluralA(ary)
    Number.prototype.pluralA = function (ary)
      return this.plural(ary[0], ary[1], ary[2])
    
  3. popCount()
    Number.prototype.popCount = function() {
      var v = this.valueOf();
      v = v - ((v >> 1) & 0x55555555);                
      v = (v & 0x33333333) + ((v >> 2) & 0x33333333); 
      return ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
    };
    
  4. powerOf(power)
    Number.prototype.powerOf = function(power) {
      return Math.pow(this, power);
    };
    
  5. randStr()
    Number.prototype.randStr = function() {
        var alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
        var res = '';
        for(var i = 0; i < this; i++) {
            res += alpha[Math.floor(Math.random() * alpha.length)];
        return res;
    
  6. repeat(n)
    Number.prototype.repeat = function(n){
      return this.toString().repeat(n);
    
  7. repr()
    Number.prototype.repr = function () {
        var digits = (arguments.length > 0)? arguments[0] : undefined;
        if (typeof digits !== "number") {
            return Number(this);
        if (digits <= 0) {
            return Math.round(this);
        var factor = Math.pow(10, digits);
    ...
    
  8. reprLocale()
    Number.prototype.reprLocale = function () {
        var result,
            digits = (arguments.length > 0)? arguments[0] : undefined,
            number = String(this.repr(digits)),
            int = number.split(".")[0],
            intparts = [],
            float = (number.indexOf(".") >= 0)? number.split(".")[1] : undefined;
        while (int.length > 0) {
            if (int.length <= 3) {
    ...
    
  9. reverse()
    Number.prototype.reverse = function() {
      return parseInt(this.toString().split('').reverse().join(''), 10);