Skip to content

Instantly share code, notes, and snippets.

@masterots
Created April 30, 2015 22:00
Show Gist options
  • Save masterots/df5d7512d96137f8148b to your computer and use it in GitHub Desktop.
Save masterots/df5d7512d96137f8148b to your computer and use it in GitHub Desktop.
Project Euler - largest palindrome
function largestPalindrome(lowNum, highNum) {
var max = 0;
for (var i = highNum; i >= lowNum; i--) {
for (var j = i; j >= lowNum; j--) {
var mul = j * i;
if (isPalindrome(mul) && mul > max) {
max = i * j;
}
}
}
return max;
}
function isPalindrome(i) {
i = '' + i;
return i === i.split("").reverse().join("");
}
console.log(largestPalindrome(100,999));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment