3-Digit Palindrome

JavaScript performance comparison

Test case created by Josh

Info

largest palindrome from the product of two 3-digit numbers

Preparation code

<div id="answer"></div>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Palindrome
var Palindrome = {
 i: 999,
 j: 999
};

Palindrome.testPalindrome = function(result) {
 var test = result.split("");
 test.reverse();

 if (result === test.join("")) {
  return true;
 } else {
  return false;
 }
};

Palindrome.runLoop = function() {
 var x = this.i - 10,
     result = 0;

 for (this.i; this.i > x; this.i = this.i - 1) {
  result = this.i * this.j;

  if (this.testPalindrome(result.toString()) === true) {
   return this.Win(this.i, this.j, result);
  }
 }

 this.j = this.j - 1;
 this.i = this.j;
 this.runLoop();
};

Palindrome.Win = function(i, j, result) {
 // 924 multipled by 932 is equal to 861168, the largest palindrome made from the product of two 3-digit numbers
 document.getElementById('answer').innerHTML = i + " multipled by " + j + " is equal to " + result + ", the largest palindrome made from the product of two 3-digit numbers";
};

(function() {
 Palindrome.runLoop();
})();
pending…
nothing
return false;
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment