How to check whether a numbers are palindrome in base 10 and base 2 with Node.js

1 Answer

0 votes
function isBinaryRepresentationOfNumberPalindrome(num) {
    let binary = num.toString(2);
    console.log(binary);
 
    return binary == [...binary].reverse().join('');
}

function isPalindrome(num) {
    let strnum = num.toString();
     
    return strnum === [...strnum].reverse().join('');
}
         
const num = 585; // 1001001001
 
console.log(isPalindrome(num) && isBinaryRepresentationOfNumberPalindrome(num) ? "yes" : "no");

 
 
     
/*
run:
     
1001001001
yes

*/

 



answered Jan 8, 2024 by avibootz
edited Jan 8, 2024 by avibootz
...