Javascript DSA — 03 : Integer reversal

Yuvaraj S
1 min readNov 23, 2023

--

In our previous blog we have learnt about

Javascript DSA — 02 : Palindrome

Today let’s deal with Integer reversal,

“Given an integer, return an integer that is the reverse ordering numbers ie, revese(-51) = -15, reverse(-90) = -9, reverse(80) = 8”

Let’s quickly solve the question!!

In our previous blogs we understood how to reverse a string, here’s the same one but we are converting into string and string to array to reverse.
The little trick here is,
`parseInt(‘330-’)` will give the output 330, which means parseInt will take the first possible numbers, ie, parseInt('220-dskd') will give me 220.

And the second trick is Math.sign(200) will give 1 on passing negitive number we will get -1. Just to handle the sign we are using this method.

NEXT lesson :

--

--

Yuvaraj S

Passionate Angular Developer. I post programming content regarding, Frontend Development with working example. ie, Angular, Html, CSS, Javascript