Skip to content

Instantly share code, notes, and snippets.

@DiegoPinho
Created August 7, 2018 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DiegoPinho/7af942a0e7ca987bc1e0d37819ffaf98 to your computer and use it in GitHub Desktop.
Save DiegoPinho/7af942a0e7ca987bc1e0d37819ffaf98 to your computer and use it in GitHub Desktop.
function findMajorPalindromFor(digits) {
var n1 = Math.pow(10, digits) - 1;
for(var n2 = n1; n2 => 0; n2--) {
var value = n1 * n2;
if(isPalindrom(value)) {
console.log(`${n1} x ${n2} = ${value}`);
break;
}
}
}
function isPalindrom(num) {
var str = num.toString();
return str == str.split('').reverse().join('');
}
findMajorPalindromFor(3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment