BE AWARE: this is working solution. If you want to solve it on your own, consider not to read the code.

Discussions related to implementation:

About code structure

Optimization

Thanks to all who answered my questions, feel like I learned much when solving relatively easy problem.

Would appreciate feedback not only about algorithm, but about comments in code.

I am using comments like I saw in MIT problem sets plus some improvisation. Course “Introduction to programming using Python”. Such problem sets are on MIT open course ware, I am sure anybody who wants can find it(I am not sure if link to such resource is appropriate for this forum).

Are there any conventional rules in JS in terms of commenting I am not using and should use?

Implementation:

```
function isNumberPalindromic(num) {
/*function was originally implemented to work with strings
was optimized to only work with numbers:
was renamed from palindrome() to isNumberPalindromic()
part of code for formatting strings(regexp) was replaced
Expected input:
num: natural number
Expected output:
true if number is palindromic
false otherwise
*/
let formattedNum = ""+num;
if (formattedNum=='' || formattedNum.length == 1) {
return true;
}
else {
return formattedNum[0] == formattedNum[formattedNum.length - 1] &&
isNumberPalindromic(formattedNum.slice(1,-1));
}
}
/*Unit testing
testing environment: onecompiler.com
console.log(isNumberPalindromic(9009));//true
console.log(isNumberPalindromic(9116));//false
console.log(isNumberPalindromic(9345));//false
*/
function largestPalindromeProduct(n) {
/*
Expected input:
n: natural number > 0, number of digits
Expected output:
number, the largest palindromic product of 2 n-digit numbers
*/
let result = 0;
for (let i = Math.pow(10, (n - 1)); i < Math.pow(10, n); i++) {
// if i == 2 >>> start step i = 10; end step i < 100
for (let j = i; j < Math.pow(10, n); j++) {
// j = i >>> exploiting math pattern to reduce number of checks
// TODO: try to estimate big O notation for these nested loops for the sake of learning
let tempResult = i * j; /*TODO:
figure out what's best: use variable or end up with more multiplications*/
if (tempResult > result && isNumberPalindromic(tempResult)) {
result = tempResult;
}
}
}
return result;
}
//all tests passed at fCC
```