Convert a Roman numeral string to an integer
Implement a function romanToInteger that converts a Roman numeral string to an integer. Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. The Roman numerals article covers the subtractive rules, such as IV and IX.
The rules for Roman numeral conversion are as follows:
I can be placed before V (5) and X (10) to make 4 and 9.X can be placed before L (50) and C (100) to make 40 and 90.C can be placed before D (500) and M (1000) to make 400 and 900.Function Signature:
function romanToInteger(str: string): number
Example Usage:
const result = romanToInteger("MCMXCIV");
console.log(result); // Output: 1994
Your solution should handle strings representing Roman numerals in the range from 1 to 3999. The input string is guaranteed to be a valid Roman numeral up to 3999.