Longest Chunked Palindrome Decomposition LeetCode solution in JavaScript
1var longestDecomposition = function (text) {2var i = 1;3var output = 0;4while (i < text.length) {5if (text.substring(0, i) == text.substring(text.length - i)) {6output += 2; //add 2 to simulate adding to both sides of output array7text = text.substring(i, text.length - i); //cut text to simulate popping off of both sides8i = 1;9} else {10i++;11}12}1314return text ? output + 1 : output; //if there's any text leftover that didn't have a match, it's the middle and would add 1 to output array15};