This was my solution in javascript.

```
/**
* @param {number} x
* @return {number}
*/
var reverse = function(x) {
if(parseInt(x) === 0 || parseInt(x) == 'NaN') return 0;
let result = (x > 0) ? '' : '-';
while(x >= 1 || x <= -1 ) {
x = parseInt(x);
result += Math.abs(x%10);
x = x/10;
}
result = parseInt(result);
return (result >> 0 === result) ? result : 0;
};
```