/** * @param {number}x * @return {number} */ var reverse = function (x) { let result = 0; while (x !== 0) { const lastDigit = x % 10; result = result * 10 + lastDigit; x = Math.trunc(x / 10); }
if (result < (-1 * Math.pow(2, 31)) || result > (Math.pow(2, 31) - 1)) { return0; } return result; };