Ad
Code
Diff
  • var solution = (s) => {
        let total = 0;
        for(let index = 0; index < s.length; index++){
            if((s.length >= index + 1) && (romanMap[s[index]] < romanMap[s[index + 1]])){ 
                total += romanMap[s[index + 1]] - romanMap[s[index]];
                index ++;
            } else { 
                total += romanMap[s[index]];
            }
        }
        return total;
    };
    
    const romanMap = {
        'I': 1,
        'V': 5,
        'X': 10,
        'L': 50,
        'C': 100,
        'D': 500,
        'M': 1000
    };
    
    • package kata
    • var solution = (s) => {
    • let total = 0;
    • for(let index = 0; index < s.length; index++){
    • if((s.length >= index + 1) && (romanMap[s[index]] < romanMap[s[index + 1]])){
    • total += romanMap[s[index + 1]] - romanMap[s[index]];
    • index ++;
    • } else {
    • total += romanMap[s[index]];
    • }
    • }
    • return total;
    • };
    • func Decode(roman string) int {
    • return 0
    • }
    • const romanMap = {
    • 'I': 1,
    • 'V': 5,
    • 'X': 10,
    • 'L': 50,
    • 'C': 100,
    • 'D': 500,
    • 'M': 1000
    • };