Completed functionality for palindromeChainLength in JS.