Reverse decimal digits in javascript

后端 未结 14 1115
灰色年华
灰色年华 2021-02-05 16:24

How do I reverse the digits of a number using bitwise?

input:

x = 123; 

output:

x = 321; 
14条回答
  •  不要未来只要你来
    2021-02-05 17:16

    Reversing The Positive/ Negative Integer Number

    function reverseInt(n) {
     return parseInt(n.toString().split('').reverse().join()) * Math.sign(n)
    }
    

    If n is -5, then Math.sign(n)==> will return -1

    If n is 5, then Math.sign(n)==> will return 1

提交回复
热议问题