/**
* @param {number} x
* @return {number}
*/
var reverse = function (x) {
let str = (Math.abs(x) + '').split('').reverse(), result = '';
for (var i in str) {
result += str[i];
}
result *= x > 0 ? 1 : -1;
if (result > (Math.pow(2, 31) - 1) || result < Math.pow(2, 31) * -1) {
return 0;
}
return result;
};
var x = -126845314;
reverse(x);