11. Write a JavaScript function that checks whether a passed string is palindrome or not?

Provided test cases

  • palindrome(“race car”) should return true
  • palindrome(“not a palindrome”) should return false
  • palindrome(“A man, a plan, a canal. Panama”) should return true
  • palindrome(“never odd or even”) should return true
  • palindrome(“nope”) should return false
  • palindrome(“almostomla”) should return false
  • palindrome(“My age is 0, 0 si ega ym.”) should return true
  • palindrome(“1 eye for of 1 eye.”) should return false
  • palindrome(“0_0 (: /-\ :) 0–0”) should return true
  




        function palindrome(str) {

        var len = str.length;
        var mid = Math.floor(len/2);
        var retVal=true;
        for ( var i = 0; i < mid; i++ ) {
        if (str[i] !== str[len - 1 - i]) {
        //  return false;
        retVal = false;
        }
        }
        if(retVal == true){
        console.log(`${str} is Palindrome`);
        }
        else{
        console.log(`${str} is not Palindrome`);

        }

        //return true;
        }

        palindrome("madam");
        palindrome("run");



        function isPalindrome(string) {
        if (string == string.split('').reverse().join('')) {
        console.log(string + ' is palindrome.');
        }
        else {
        console.log(string + ' is not palindrome.');
        }
        }

        isPalindrome("madam");
        isPalindrome("run");