Nodejs Number Calculate ordenar()

Here you can find the source of ordenar()

Method Source Code

#!/usr/bin/env node//from   w  w  w  .  j av  a 2s.c  o  m
/*
# 052-samedigits.rb
#   juanfc 2010-12-08
# http://projecteuler.net/index.php?section=problems&page=2
# 52.
# Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x,
# contain the same digits in some order.
*/

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;
var s;
do {
  x+= 1;
  s= x.ordenar();
  done= (s === (2*x).ordenar()) && (s === (3*x).ordenar()) && (s === (4*x).ordenar()) && (s === (5*x).ordenar()) && (s === (6*x).ordenar());
} while (!done);

console.log([x,2*x,3*x,4*x,5*x,6*x]);

Related

  1. min(minimum)
    Number.prototype.min = function(minimum) {
        if (this.valueOf() < minimum){
          return minimum;
        } else {
          return this.valueOf();
    };
    
  2. modNumber.prototype.mod || (n)
    Number.prototype.mod = Number.prototype.mod || function(n) {
      return ((this%n)+n)%n;
    
  3. 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));
    ...
    
  4. next()
    Number.prototype.next = function(){
        return this+1;
    };
    
  5. normalize(num)
    Number.prototype.normalize = function(num) {
      return this*180/num;
    };
    
  6. 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() {
    ...
    
  7. 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'; }
    ...
    
  8. parseNumber(x)
    function parseNumber(x){
      if(!isNaN(x)) return x;
      return parseFloat(x.substring(1, x.length - 1));
    
  9. percentage(val)
    Number.prototype.percentage = function(val){
      return this * (val/100);
    };