SOURCE

var myAtoi = function(str) {
    var sign = 1;
    var temp = '';
    const INT_MAX = Math.pow(2,31) -1;
    const INT_MIN = -1 * Math.pow(2,31);
    if(str.lenght == 0) {
        return 0;
    }
    for (var i = 0; i < str.length; i++) {
        console.log(str[i]);
        if (str[i] == '-') {
            sign = -1;
        }
        if ('0' <= str[i] && str[i] <= '9') {
            temp += str[i];
        }
    }
    console.log(temp);
    if (temp == '') {
        return 0;
    }
    temp = parseInt(temp);
    if (temp > INT_MAX) {
        return INT_MAX;
    }
    if (temp < INT_MIN) {
        return INT_MIN;
    }
    return sign*temp;
};

console.log(myAtoi("world 93hx"));
console 命令行工具 X clear

                    
>
console