Skip to content

Instantly share code, notes, and snippets.

@nefarioustim
Created July 31, 2012 17:19
Show Gist options
  • Save nefarioustim/3218671 to your computer and use it in GitHub Desktop.
Save nefarioustim/3218671 to your computer and use it in GitHub Desktop.
Find the largest palindrome made from the product of two 3-digit numbers
function getPalindrome() {
var product, y,
x = 999,
largest = 0;
while (x > 99) {
y = x;
while (y > 99) {
product = x * y;
if (product <= largest) break;
if (product.toString() === product.toString().split("").reverse().join(""))
largest = product;
y--;
}
x--;
}
return largest;
}
console.log(getPalindrome());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment