SOURCE

(function (win, doc) {
    
    var romanToInt = function (s) {
        let i , num = 0;
        for (i=0; i < s.length - 1; i++) {
            if (i == s.length - 1) continue;
            let currNum = getValue(s[i]);
            console.log('currNum:' + currNum);
            let nextNum = getValue(s[i + 1]);
            console.log('nextNum:' + nextNum);
            console.log('totalNum:' + num+'\r\n-------------');
            if (currNum < nextNum) {
                num -= currNum;
            } else {
                num += currNum;
            }
        }
        num += getValue(s[s.length - 1]);
        return num;
    };

    function getValue(ch) {
        switch (ch) {
            case 'I': return 1;
            case 'V': return 5;
            case 'X': return 10;
            case 'L': return 50;
            case 'C': return 100;
            case 'D': return 500;
            case 'M': return 1000;
            default: return 0;
        }
    }

    console.log(romanToInt("III"));
})(window, document);
console 命令行工具 X clear

                    
>
console