로마 디지털 변환

function convert(arabic){
        var alpha = [ 'I', 'V', 'X', 'L', 'C', 'D', 'M' ], roman = "", bit = 0;
        while (arabic > 0){  
            var tempnum = arabic % 10;
            switch (tempnum){  
                case 3:{   
                    roman = alpha[bit] + roman;  
                    tempnum--;
                }  
                case 2:{  
                    roman = alpha[bit] + roman;  
                    tempnum--;
                }  
                case 1:{  
                    roman = alpha[bit] + roman;  
                    break;  
                }  
                case 4:{  
                    roman = alpha[bit + 1] + roman;
                    roman = alpha[bit] + roman;  
                    break;  
                }  
                case 8:{  
                    roman = alpha[bit] + roman; 
                    tempnum--;
                }  
                case 7:{  
                    roman = alpha[bit] + roman; 
                    tempnum--;
                }  
                case 6:{  
                    roman = alpha[bit] + roman;  
                    tempnum--;
                }  
                case 5:{  
                    roman = alpha[bit + 1] + roman;  
                    break;  
                }  
                case 9:{ 
                    roman = alpha[bit + 2] + roman; 
                    roman = alpha[bit] + roman; 
                    break;  
                }  
                default:{  
                    break;  
                }  
            }  
            bit += 2;  
            arabic = Math.floor(arabic / 10);  
        }  
        return roman;
    }
convert(3999);

좋은 웹페이지 즐겨찾기