constreverse=n=>{conststr=""+Math.abs(n);// convert absolute value to stringconstreversed=str.split("")// get array of digit characters.reverse()// reverse it.join("");// join into string again;constnum=+reversed;// convert integerreturn(n<0?-1:1)*num;// multiple by -1 if needed}
Hi Urfan, I want to suggest another solution:
even shorter:
Cheers.
Your solution does not cover the condition to return 0 if number is out of bound, that's why numeric approach is more feasible here.
let reversed = x.toString().split("").reverse().join("");
return parseInt(reversed) * Math.sign(x);