```
/**
* @param {number} x
* @return {number}
*/
var reverse = function(x) {
const INT_MAX = 2147483647;
const INT_MIN = -2147483647;
var reversed = 0;
while (x != 0) {
reversed *= 10;
reversed += x % 10;
x -= x % 10;
x /= 10;
}
if(reversed <= INT_MAX && reversed >= INT_MIN)
return reversed;
else
return 0;
};
```