There is a number:

var chislo = 123456

How do you flip it – reflect it?


Convert the number to a string


Now we have a string data type. A string is an iterable object, so it can be cast to an array:


Each “digit” now lies under a separate array element. Let’s reverse() this array


Now we just need to glue all the individual lines into one


And now we have a string variant of the inverted number. Now all we have to do is to convert the string to a number:


All done!

All commands in the browser console:

Leave a Reply

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

You May Also Like