Skip to content

Instantly share code, notes, and snippets.

@gavinsykes
Created April 29, 2020 21:26
Show Gist options
  • Save gavinsykes/c7762be9246d0db0fae91fc3650b9d3e to your computer and use it in GitHub Desktop.
Save gavinsykes/c7762be9246d0db0fae91fc3650b9d3e to your computer and use it in GitHub Desktop.
const largestPalindromeProduct = num => {
let n = +num;
let result = 0;
if (n < 1 || !Number.isInteger(n)) {
return undefined;
}
for (let i = 1; i < 10**n;i++) {
for (let j = 1; j < 10**n;j++) {
if (isPalindrome(i*j) && i*j > result) {
result = i*j;
}
}
}
return result;
}
const isPalindrome = s => !s.toString().toLowerCase().split('').filter(i => /\S/.test(i)).some((c,i,a) => c == a[a.length - 1 - i]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment