Palindrome

Question: Write a Program to check whether a String is Palindrome or Not

A palindrome is a word, phrase, number or sequence of words that reads the same backward as forward.

Example:
  • anna
  • civic
  • level
  • madam
  • mom
  • noon
  • racecar
  • refer
  • stats
Method 1
//Using inbuilt functions

function checkPalindrome(str) {
  let reversedStr=str.split("").reverse().join("");
  if(str===reverseStr) {
    return "It is a palindrome";
  }
  return "It is not a palindrome";
 }
 
 console.log(checkPalindrome("madam"));
 //Prints: It is a palindrome
 
 console.log(checPalindrome("hello"));
 //Prints: It is not a palindrome
  
Method 2
//Without using inbuilt functions

function checkPalindrome(str) {
  const len = str.length;
  for (let i = 0; i < len / 2; i++) {
    if (str[i] !== str[len - 1 - i]) {
      return "It is not a palindrome";
    }
  }
  return "It is a palindrome";
}

console.log(checkPalindrome("madam"));
 //Prints: It is a palindrome
 
 console.log(checPalindrome("hello"));
 //Prints: It is not a palindrome