JavaScript code please

Asked by Ashish Yadav about 5 months ago

0

Program to Check Whether a Number is Palindrome or Not.If the number is palindrome print true else print false. i/p 121 o/p true

1 Answer

    0
    function palindrome(str) {
        if (str == str.split('').reverse().join('')) {
            return true;
        } else {
            return false;
        }
    }
    
    console.log(palindrome('121'));
    console.log(palindrome('racecar'));
    console.log(palindrome('yourname'));
    

    To find the plaindrome we're comparing the string input to the reverse version of the string.

    If both of the match, then the string is a plaindrome.

    We are reversing the contents of the string using built-in JavaScript methods of String and Array.

    @pranavtechie

    Pranav Mandava

    @pranavtechie

    Your answer