Nodejs Number Value Check even()

Here you can find the source of even()

Method Source Code

var puts = require("sys").puts;

Number.square = function(n) {
  return n * n// www. j a v  a 2s . c om
}

Number.even = function(n) {
  return n % 2 == 0
}

Number.odd = function(n) {
  return !this.even(n)
}

Number.prototype.even = function() {
  return this.constructor.even(this)
}

Number.prototype.odd = function() {
  return this.constructor.odd(this)
}

Array.prototype.sortAsc = function() {
  return this.sort(function(x, y){
    if(x < y) {
      return -1
    } else if(y < x) {
      return 1
    } else {
      return 0
    }
  })
}

Array.prototype.sortDesc = function() {
  return this.sort(function(x, y){
    if(x < y) {
      return 1
    } else if(y < x) {
      return -1
    } else {
      return 0
    }
  })
}

puts([2,1,4,3].map(Number.square).filter(Number.even).sortDesc())

Related

  1. odd()
    Number.prototype.odd = function(){
      return ( ( this % 2 ) == 1 )
    
  2. isBetween(l,h)
    Number.prototype.isBetween = function(l,h){
      return (this >= l.val() && this <= h.val());
    
  3. isBetween(min, max, inclusive)
    Number.prototype.isBetween = function (min, max, inclusive) {
      return inclusive
        ? this >= min && this <= max
        : this > min && this < max;
    };
    
  4. isBetweenisBetween(a, b)
    Number.prototype.isBetween = function isBetween(a, b) {
      if(a <= this) {
        return this <= b;
      return this >= b;
    
  5. even()
    Number.prototype.even = function(){
        return (this % 2 === 0);
    };
    
  6. isNumber()
    String.prototype.isNumber = function(){
      return !isNaN(this);
    };
    
  7. isNumber()
    String.prototype.isNumber = function(){
      var pattern=/^[+\-]?\d+(.\d+)?$/;
      flag=pattern.test(this);
      if(flag) return true;
      return false;
    
  8. isNumber()
    String.prototype.isNumber = function (){
        var str = this;
        return !isNaN(str);
    
  9. isNumber()
    String.prototype.isNumber = function()
      return (/^\d+$/.test(this.Trim()));