Nodejs Number Calculate hasDiv( n )

Here you can find the source of hasDiv( n )

Method Source Code

Number.prototype.hasDiv = function( n ) {
  return Number.isInteger( this / n )
}

function sum( ary ) {
  var out = 0//from www . jav  a2 s  .co m
  for (var n in ary)  {
    out += ary[n]
  }
  return out
}
function divisors( n ) {
  out = []
  for ( var i = 1; i < n; i++ ) {
    if ( n.hasDiv( i ) ) {
      out.push( i )
    }
  }
  return out
}

function isPerfectN( n ) {
  if (sum(divisors( n)) == n) {
    return true
  }
  else {
    return false
  }
}

function perfectsUnder( n ) {
  ary = [ 1 ]
  for( var i = 1; i < n; i++ ) {
    if ( isPerfectN( i ) ) {
      ary.push( i )
    }
  }
  return ary
}

Related

  1. getHisByMs()
    Number.prototype.getHisByMs=function(){
        var ms=this;
        var date=new Date(ms);
        var his=[];
        his.push(Number(date.getHours()).addZero());
        his.push(Number(date.getMinutes()).addZero());
        his.push(Number(date.getSeconds()).addZero());
        return his;
    
  2. getPrecisiongetPrecision(length)
    Number.prototype.getPrecision = function getPrecision(length) {
        var value = parseFloat(this);
        if (Number.isFloat(value)) {
            return value.toString().split(".")[1].length;
        return 0;
    };
    
  3. getValue(arguments)
    var BigNumber = function(n){
      this.value = n.toString();
      this.getValue = function(){
        return this.value;
      this.getRealValue = function(){
        return Number(this.value);
      this.add = function(bnum){
    ...
    
  4. greaterThan(num)
    Number.prototype.greaterThan = function(num) {
        return this > num;
    
  5. gt(right) return this > right };
    Number.prototype.gt = function(right) { return this > right };
    Number.prototype.ge = function(right) { return this >= right };
    Number.prototype.lt = function(right) { return this < right };
    Number.prototype.le = function(right) { return this <= right };
    Number.prototype.eq = function(right) { return this == right };
    Number.prototype.ne = function(right) { return this != right };
    
  6. 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
    
  7. 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);
    ...
    
  8. intToHSL()
    Number.prototype.intToHSL = function() {
        var shortened = this % 360;
        return "hsl(" + shortened + ",45%,56%)";
    };
    
  9. max(maximum)
    Number.prototype.max = function(maximum) {
        if (this.valueOf() > maximum){
          return maximum;
        } else {
          return this.valueOf();
    };