I. Details of the problem:
You are given a 32-bit signed integer x that returns the result of reversing the numeric portion of x. If the inverted integer exceeds the range of 32-bit signed integers [−231, 231 − 1], 0 is returned. Assume that the environment does not allow storage of 64-bit integers (signed or unsigned).
Ii. My answer:
/** * @param {number} x * @return {number} */ var reverse = function(x){// Integer turn + + string segmentation + inversion, joining together the let f = parseInt (x.t oString (). The split (' '). Reverse () join (")); If (x < 0) f = -f; return f <= -2147483648 || f >= 2147483647 ? 0 : f };Copy the code
Iii. Reference Answers:
var reverse = function (x) {
let y = parseInt(x.toString().split("").reverse().join(""));
if (x < 0)
y = - y;
return y > 2147483647 || y < -2147483648 ? 0 : y;
};
Copy the code
Iv. Summary and Suggestions:
Learn and associate the words commented in the above code block: some of the manipulation methods in the basic usage of JS.