Check if Palindrome - String

ZeeshanAli-0704 - Aug 23 '22 - - Dev Community
var isPalindrome = function (x, moves) {
  x = x.toString();
  let initial = 0;
  let last = x.length - 1;
  let isPalindrome = true;
  for (let i = 0; i < x.length; i++) {
    if (x[initial] == x[last] && initial < last) {
      initial++;
      last--;
    } else if (initial > last) {
    } else if (moves === 1 && Math.abs(x.length % 2) == 1) {
      isPalindrome = false;
      break;
    }
  }
  return isPalindrome;
};

console.log(isPalindrome("abba"))
Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .