Javascript Array isPalindromic()

Description

Javascript Array isPalindromic()


function arraysEqual(a,b) { return !!a && !!b && !(a<b || b<a); }


Array.prototype.isPalindromic = function() { return this.concat().equals(this.reverse()); }
Array.prototype.equals = function(b) {
  return arraysEqual(this, b);
}

function getHighestPalindrome () {
 var max = 1000;//from  w  w  w .  jav  a 2 s .c om
 var min = 100;
  var palindrome = 0;
 for (var n = max; max >= n && n >= min; n--) {
    for (var m = max; max >= m && m >= min; m--) {
      var p = n * m;
      if (p.toString().split("").isPalindromic()) {
        if (p > palindrome) {
          palindrome = p;
        }
      }
    }
  }
  return palindrome;
}



PreviousNext

Related