lewandy
7/24/2019 - 3:21 AM

Palindrome

Palindrome is an algorithm that validate if a string is same between reverse of it.

//Palindrome problem with recursivity

function IsPalindrome(word = "",p1,p2){
    if (word.length % 2 !== 0){
        let halfLetter = Math.round((word.length) / 2) - 1;
        if (word[p1] == word[p2]){
            if (p1 == halfLetter && p2 == halfLetter){
                console.log("Is palindrome");
                return 1;
            }else{
                IsPalindrome(word,p1+1,p2-1);
            }
        }else{
            console.log("Not is palindrome");
            return;
        }
    }else{
        console.log("Not is palindrome");
        return;
    }
}

var word = "ababhba";
IsPalindrome(word,0,word.length -1);