Nodejs Number Calculate modNumber.prototype.mod || (n)

Here you can find the source of modNumber.prototype.mod || (n)

Method Source Code

/**//  w  w  w. j  a va  2  s.c om
 * Always positive modulus
 * @param {int} n Modulus
 * @returns {int} this modulo n
 */
Number.prototype.mod = Number.prototype.mod || function(n) {
   return ((this%n)+n)%n;
}

Related

  1. hasMult( n )
    Number.prototype.hasMult = function( n ) {
      return Number.isInteger( this / n )
    function fun100() {
      out = []
      for ( var i = 1; i <= 100; i++ ) {
        if ( i.hasMult(3) ) {
          out.push['Fizz']
        else if ( i.hasMult(5) ) {
          out.push['Buzz']
        else if ( i.hasMult(5) && i.hasMolt(3) ) {
          out.push["Fizzbuzz"]
        else {
          out.push( i.toString() )
      return out
    
  2. int()
    var num = 5;
    Number.prototype.int = function(){ 
          return parseInt(this) ;
    Number.prototype.float = function(){ 
          return this.toFixed(2);
    console.log(num.float());
    console.log(num);
    ...
    
  3. intToHSL()
    Number.prototype.intToHSL = function() {
        var shortened = this % 360;
        return "hsl(" + shortened + ",45%,56%)";
    };
    
  4. max(maximum)
    Number.prototype.max = function(maximum) {
        if (this.valueOf() > maximum){
          return maximum;
        } else {
          return this.valueOf();
    };
    
  5. min(minimum)
    Number.prototype.min = function(minimum) {
        if (this.valueOf() < minimum){
          return minimum;
        } else {
          return this.valueOf();
    };
    
  6. mult()
    Number.prototype.mult = function() {
        var w = this;
        for (var i = 0; i < arguments.length; i += 1)
            w *= arguments[i];
        return w;
    var n = 12;
    console.log(n.mult(2, 3));
    console.log((5).mult(2, n));
    ...
    
  7. next()
    Number.prototype.next = function(){
        return this+1;
    };
    
  8. normalize(num)
    Number.prototype.normalize = function(num) {
      return this*180/num;
    };
    
  9. ordenar()
    #!/usr/bin/env node
    Number.prototype.ordenar = function () {
      return this.toString().split('').sort(up).join('');
    };
    function up (a,b) {
      return a > b ? 1 : a < b ? -1 : 0;
    var x = 0;
    var done= false;
    ...