[removed] How to reverse a number?

前端 未结 10 952
余生分开走
余生分开走 2020-11-29 11:54

Below is my source code to reverse (as in mirror) the given number. I need to reverse the number using reverse method of arrays.

var a = prompt(\"Enter a va         


        
10条回答
  •  囚心锁ツ
    2020-11-29 12:29

    Or, as a one-liner ( x contains the integer number to be inversed):

    revX=x.toFixed(0).split('').reverse().join('')-0;
    

    The number will be separated into its individual digits, reversed and then reassembled again into a string. The -0 then converts it into a number again.

提交回复
热议问题