Created
July 31, 2012 17:19
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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