Create a JavaScript function that takes an input string and returns its longest palindrome substring.

function longestPalindrome(str) {
  if (!str || str.length <= 1) {
    return str;
  }

  let longest = '';

  for (let i = 0; i < str.length; i++) {
    const palindromeOdd = expandAroundCenter(str, i, i);
    const palindromeEven = expandAroundCenter(str, i, i + 1);

    const longerPalindrome =
      palindromeOdd.length > palindromeEven.length
        ? palindromeOdd
        : palindromeEven;

    if (longerPalindrome.length > longest.length) {
      longest = longerPalindrome;
    }
  }

  return longest;
}

function expandAroundCenter(str, left, right) {
  while (left >= 0 && right < str.length && str[left] === str[right]) {
    left--;
    right++;
  }

  return str.slice(left + 1, right);
}

console.log(longestPalindrome("babad")); // Output: "bab" or "aba"
console.log(longestPalindrome("cbbd")); // Output: "bb"
console.log(longestPalindrome("abcdefg")); // Output: "a"