Reverse decimal digits in javascript

后端 未结 14 946
灰色年华
灰色年华 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 16:58

    This takes Number x as a parameter and returns the reversed number.

    const reverse = (x) => Number(x.toString().split("").reverse().join(""));

提交回复
热议问题