javascript – Find palindromes on a rotated circular rope

I am trying to face a programming challenge to determine how many palindromes exist in a given string that is being rotated character by character. My solution works, but it's too slow, and I'm struggling to optimize it.

For example, the chain "cacbbba" would rotate 6 times and would have 3 palindromes in each chain.

  1. cacbbba (3 palindromes)
  2. acbbbado (3 palindromes)
  3. cbbbaCalifornia (3 palindromes)
  4. bbbacac (3 palindromes)
  5. bbacacb (3 palindromes)
  6. licensed in letterscacbb (3 palindromes)
  7. acacbbb (3 palindromes)
circular functionPalindromes (s) {
const k = s.length;
result of const = [];
const isPalindrome = (str) => {
const len ​​= str.length;

for (be i = 0; i < len / 2; i++) {
            if (str[i] !== str[len - 1 - i]) {
                return false;
            }
        }

        return true;
    };
    const subs = (s) => {
leaves max = 0;

for (be i = 0; i <s.length; i ++) {
for (be j = 1; j <= s.length - i; j ++) {
const sub = s.substring (i, i + j);

if (sub.length < 2) continue;

                if (isPalindrome(sub) && sub.length > max) {
max = sub.length;
}
}
}

return max;
};

for (be i = 0; i <k; i ++) {
result.push (subs (s.substring (i, k) + s.substring (0, i)));
}

return result
}
console.log (circularPalindromes (& # 39; cacbbba & # 39;));