Javascript Number reverse()

Description

Javascript Number reverse()


Number.prototype.reverse = function() {
  return parseInt(this.toString().split('').reverse().join(''), 10);
}

Number.prototype.isPalindrome = function() {
  return this == this.reverse();
}

var max = 0/*  w  ww. j  a  v a 2s  . c  o m*/
  , x;

for (var i = 100; i < 999; i++) {
  for (var j = i; j < 999; j++) {
    x = i * j;
    if (x.isPalindrome() && x > max) {
      max = x;
    }
  }
}

console.log(max);

Javascript Number reverse()

var palindromeChainLength = function(n, s=0) {
  return n == (n).reverse() ? s : palindromeChainLength(n + (n).reverse(), s+1)
};


Number.prototype.reverse = function() { 
  return parseInt( 
                  String(this).split('')
                              .reverse()
                              .join('')
                  )            //  www  .j a  va 2s. c  om
}



PreviousNext

Related