You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// If the integer is out of the 32-bit signed integer range [-2^31, 2^31 - 1], then clamp the integer so that it remains in the range. Specifically, integers less than -2^31 should be clamped to -2^31, and integers greater than 2^31 - 1 should be clamped to 2^31 - 1.
var myAtoi = function(s) {
var val = parseInt(s);
var result = val ? val : 0;
var lowerLimit = 2**31 * -1;
var upperLimit = 2**31 - 1;
if(result < 0) {
result = result <= lowerLimit ? lowerLimit : result;
} else {
result = result >= upperLimit ? upperLimit : result;