Nodejs Number Calculate timesTwo(x)

Here you can find the source of timesTwo(x)

Method Source Code

var x = new Number(2);
console.log(x);/*from   w ww.jav  a 2s  .co  m*/

//Add a prototype
Number.prototype.timesTwo = function(x){
   return x * 2;
};

console.log(x.timesTwo(x));

console.log(Number.isNaN(x));

//Polyfill
Number.isInteger = Number.isInteger || function(x){
   return typeof x === "number" &&
   isFinite(x) &&
   Math.floor(x) === x;
};

//Get Number object value in accordance with browser settings.
console.log(x.toLocaleString());

//JS toString
console.log(x.toString());

//View object constructor
console.log(x.constructor);

Related

  1. plus(num)
    Number.prototype.plus = function(num) {
      return this + num
    };
    Number.prototype.minus = function(num) {
      return this - num
    };
    Number.prototype.multi = function(num) {
      return this * num
    debug((5).plus(3).minus(6))
    debug((5).multi((3).plus(2)))
    debug(6..multi(2..plus(2)))
    function add(x) {
      return function(y) {
        return function(z) {
          return x + y + z
    debug(add(2) + '\n\n')
    debug(add(2)(3) + '\n\n')
    debug(add(2)(3)(5) + '\n\n')
    
  2. times()
    Number.prototype.times = function () {
        return _.times(this, function (i) {
            return i;
        });
    };
    
  3. times()
    Number.prototype.times = function () {
      var a = [];
      var i = -1;
      while (++i < this) {
        a.push(i);
      return a;
    };
    
  4. timesPlusOne()
    Number.prototype.timesPlusOne = function () {
        return _.map(this.times(), function (i) {
            return i + 1;
        });
    };
    
  5. timesRepeat(f)
    Number.prototype.timesRepeat = function(f){
      for(var i=0; i<this; i++){
        f();
    
  6. clone(handler)
    Number.prototype.clone = function(handler) {
      return new this.constructor(this);
    };
    
  7. concat(value)
    Number.prototype.concat = Number.prototype.concat || function (value) {
      let number = this;
      let digits = exports.digitLength(value);
      number *= Math.pow(10, digits);
      return number + value;
    };
    
  8. cos()
    Number.prototype.cos = function() {
        return Math.cos(this);
    
  9. countDecimals()
    Number.prototype.countDecimals = function () {
        if(Math.floor(this.valueOf()) === this.valueOf()) return 0;
        return this.toString().split(".")[1].length || 0;