Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0.
Assume the environment does not allow you to store 64-bit integers (signed or unsigned).
//example 1
Input: x = 123
Output: 321
//example 2
Input: x = -123
Output: -321
//example 3
Input: x = 120
Output: 21
//example 4
Input: x = 0
Output: 0
reverse()
메소드로 뒤집는다.-2^31 ~ 2^32-1
) 를 벗어나면 0을 반환한다.var reverse = function(x) {
let str = x + '';
const strArr = str.split("");
let reversedArr = strArr.reverse();
if(reversedArr.length > 1 && reversedArr[0] === "0") reversedArr.splice(0, 1);
if(reversedArr[reversedArr.length-1] === "-") reversedArr.unshift(reversedArr.pop());
let answer = reversedArr.join("");
answer = Number(answer);
if(answer > 0x7FFFFFFF) return 0;
if(answer < -0x7FFFFFFF) return 0;
return answer;
};