Convert a Roman numeral string to its integer value.
Code
Utilitiesconst values = { I: 1, V: 5, X: 10, L: 50, C: 100, D: 500, M: 1000 };
let result = 0;
for (let i = 0; i < roman.length; i++) {
const curr = values[roman[i]], next = values[roman[i + 1]] || 0;
result += curr < next ? -curr : curr;
}
return result;Parameters
Roman numeral.
Browser·fetch() may be limited by CORS
More JavaScript Snippets
Array to Object
Convert an array of key-value pairs to an object using Object.fromEntries.
Camel Case to Words
Convert a camelCase string to separate words by inserting spaces before capitals.
Convert Currency
Convert between currencies using the Frankfurter API for live exchange rates.
CSV to JSON
Convert a CSV string to a JSON array of objects with headers as keys.
Decimal to Octal
Convert a decimal number to its octal string representation.
Integer to Roman
Convert integer to Roman numeral.