Skip to content

Instantly share code, notes, and snippets.

@MuddyBootsCode
Created April 26, 2022 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 MuddyBootsCode/d352e284885a76e837339c827e41aea5 to your computer and use it in GitHub Desktop.
Save MuddyBootsCode/d352e284885a76e837339c827e41aea5 to your computer and use it in GitHub Desktop.
function largestPalindromeProduct(n) {
let palindromes = [];
let base = Number('9'.repeat(n));
for(let i = 1; i <= base; i++){
for(let j = 1; j <= base; j++){
let product = i * j;
if (product === Number(String(product).split('').reverse().join(''))){
palindromes.push(n)
}
}
}
return Math.max(...palindromes);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment