Check if a number is palindrome or not using javascript


 const numberPalindrome = (num) => {
     let strNumber = num+'';
     let total = 0;
     let strArr = strNumber.split('');
     for (let i = 0; i < strArr.length; i++)
     {
         total += Math.abs(strArr[i]);
     }  
     strTotal = total + '';
     let revstr = strTotal.split('').reverse().join('');
     if (revstr === total.toString()) {
         return 1;
     } else{
         return 0;
     }
 }


 console.log(numberPalindrome(56)); //1
 console.log(numberPalindrome(98)); //0

Leave a Comment

Your email address will not be published. Required fields are marked *