DEV Community

ZeeshanAli-0704
ZeeshanAli-0704

Posted on

Check if Palindrome - String

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

Top comments (0)