Reverse Integer
1 var reverse = function(x) {
2 var isNeg = false,
3 res = 0,
4 temp = 0;
5
6 if (x < 0) {
7 x = -x;
8 isNeg = true;
9 }
10
11 while (x != 0) {
12 res = res * 10 + x % 10;
13 if (res > 2147483648) {
14 return 0;
15 }
16 x = Math.floor(x / 10);
17 }
18
19 return isNeg ? -res : res;
20 };