SOURCE

var Roman = ['I', 'V', 'X', 'L', 'C', 'D', 'M'];

function convert(num) {

    var e = 0, temp = num, result = [];

    while (temp > 0) {
        var n = temp % 10;
        temp = Math.floor(temp / 10);
        result.push(toRoman(n, e += 2));
    }

    // console.log(result.reverse().join(''))

}
function toRoman(num, e) {
    var i = Roman[e - 2] ,v = Roman[e - 1], x = Roman[e];

    if (num === 0) {
        return '';
    } else if (num < 4) {
        return i.repeat(num);
    } else if (num == 4) {
        return i + v;
    } else if (num == 5) {
        return v;
    } else if (num < 9) {
        return v + i.repeat(num - 5);
    } else if (num == 9) {
        return i + x;
    }
}
convert(12)
console 命令行工具 X clear

                    
>
console