Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for [old] Reverse Roman Numerals by Moff
function reverseRoman(roman) {
let result = 0;
let numerals = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000};
let subtractive_notation = {'IV': 4, 'IX': 9, 'XL': 40, 'XC': 90, 'CD': 400, 'CM': 900};
for (let n in subtractive_notation) {
if (roman.indexOf(n) > -1) {
roman = roman.replace(n, '');
result += subtractive_notation[n];
}
}
for (let n of roman) {
result += numerals[n];
}
return result;
}
July 6, 2017