{"size": 1152, "ext": "js", "max_stars_repo_path": "leetcode/8. String to Integer (atoi).js", "max_stars_repo_name": "YoungFox/webproject", "max_stars_repo_stars_event_min_datetime": "2020-08-09T00:43:18.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-09T00:43:18.000Z", "max_issues_repo_path": "leetcode/8. String to Integer (atoi).js", "max_issues_repo_name": "YoungFox/datastructure", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "leetcode/8. String to Integer (atoi).js", "max_forks_repo_name": "YoungFox/datastructure", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.5882352941, "max_line_length": 48, "alphanum_fraction": 0.3342013889}
/**
 * @param {string} str
 * @return {number}
 */
var myAtoi = function (str) {
    var possitive = 1
    var res = 0
    var hasNum = false
    var hasChar = false

    while (str.length) {
        if (/[^0-9+-\s]/.test(str[0])) {
            break
        } else {
            if (/[0-9]/.test(str[0])) {
                hasNum = true
                res = res * 10 + Number(str[0])
                str = str.slice(1)
                continue
            } else {
                if (hasNum || hasChar) {
                    break
                } else {
                    if (str[0] === '-') {
                        possitive = 0
                        hasChar = 1
                    } else if (str[0] === '+') {
                        possitive = 1
                        hasChar = 1
                    }
                    str = str.slice(1)
                    continue
                }
            }
        }
    }

    res =  possitive ? res : -res
    var max = 2**31 - 1
    var min = -(2**31)
    if(res > max){
        res = max
    }
    if(res < min){
        res = min
    }

    return res
};

console.log(myAtoi('0-12a'))