Nodejs Number Calculate plural(a, b, c)

Here you can find the source of plural(a, b, c)

Method Source Code

Number.prototype.plural = function (a, b, c)
{
   if (this % 1)//from  w  w w. java 2 s.  c om
      return b
   
   var v = Math.abs(this) % 100
   if (11 <= v && v <= 19)
      return c
   
   v = v % 10
   if (2 <= v && v <= 4)
      return b
   if (v == 1)
      return a
   
   return c
}

Related

  1. 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;
    ...
    
  2. 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() {
    ...
    
  3. ordinalize()
    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'; }
    ...
    
  4. parseNumber(x)
    function parseNumber(x){
      if(!isNaN(x)) return x;
      return parseFloat(x.substring(1, x.length - 1));
    
  5. percentage(val)
    Number.prototype.percentage = function(val){
      return this * (val/100);
    };
    
  6. pluralA(ary)
    Number.prototype.pluralA = function (ary)
      return this.plural(ary[0], ary[1], ary[2])
    
  7. popCount()
    Number.prototype.popCount = function() {
      var v = this.valueOf();
      v = v - ((v >> 1) & 0x55555555);                
      v = (v & 0x33333333) + ((v >> 2) & 0x33333333); 
      return ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
    };
    
  8. powerOf(power)
    Number.prototype.powerOf = function(power) {
      return Math.pow(this, power);
    };
    
  9. randStr()
    Number.prototype.randStr = function() {
        var alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
        var res = '';
        for(var i = 0; i < this; i++) {
            res += alpha[Math.floor(Math.random() * alpha.length)];
        return res;