Nodejs Number Calculate ordinalize()

Here you can find the source of ordinalize()

Method Source Code

// ordinalize returns the ordinal string corresponding to integer:
///* ww w.j ava2s . c o  m*/
//     (1).ordinalize()    // => '1st'
//     (2).ordinalize()    // => '2nd'
//     (53).ordinalize()   // => '53rd'
//     (2009).ordinalize() // => '2009th'
//     (-134).ordinalize() // => '-134th'
Number.prototype.ordinalize = function() {
    var abs = Math.abs(this);
    
    if (abs % 100 >= 11 && abs % 100 <= 13) {
        return this + 'th';
    }
    
    abs = abs % 10;
    if (abs === 1) { return this + 'st'; }
    if (abs === 2) { return this + 'nd'; }
    if (abs === 3) { return this + 'rd'; }
    
    return this + 'th';
};

// Alias of to_s.
Number.prototype.toParam = Number.prototype.toString;

Number.prototype.toQuery = function(key) {
   return escape(key.toParam()) + "=" + escape(this.toParam());
};

Related

  1. 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));
    ...
    
  2. next()
    Number.prototype.next = function(){
        return this+1;
    };
    
  3. normalize(num)
    Number.prototype.normalize = function(num) {
      return this*180/num;
    };
    
  4. 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;
    ...
    
  5. ordinal()
    Number.prototype.ordinal = function () {
        return this + (
            (this % 10 == 1 && this % 100 != 11) ? 'st' :
            (this % 10 == 2 && this % 100 != 12) ? 'nd' :
            (this % 10 == 3 && this % 100 != 13) ? 'rd' : 'th'
            );
    var ResetInput = function(){
        jQuery('input, textarea').each(function() {
    ...
    
  6. parseNumber(x)
    function parseNumber(x){
      if(!isNaN(x)) return x;
      return parseFloat(x.substring(1, x.length - 1));
    
  7. percentage(val)
    Number.prototype.percentage = function(val){
      return this * (val/100);
    };
    
  8. 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)
    ...
    
  9. pluralA(ary)
    Number.prototype.pluralA = function (ary)
      return this.plural(ary[0], ary[1], ary[2])