Question: In data sometimes the same product will be named with a roman numeral while other times it will be a digit.

**Example** `Samsung Galaxy SII` verses `Samsung Galaxy S2`

How can the `II` be converted to the value `2`?

Answer: 
```cs
private static int convertRomanToInt(String romanNumeral)
{
    Dictionary<Char, Int32> romanMap = new Dictionary<char, int>
    {
        {'I', 1 },
        {'V', 5},
        {'X', 10},
        {'L', 50},
        {'C', 100},
        {'D', 500},
        {'M', 1000}
    };

    Int32 result = 0;
    for (Int32 index = romanNumeral.Length - 1, last = 0; index >= 0; index--)
    {
        Int32 current = romanMap[romanNumeral[index]];
        result += (current < last ? -current : current);
        last = current;
    }

    return result;
}

```
Here is my O(n) solution in JavaScript

```js
const NUMERAL = {
    'I': 1,
    'V': 5,
    'X': 10,
    'L': 50,
    'C': 100,
    'D': 500,
    'M': 1000,
}

var romanToInt = function(s) {
    if (s.length === 1) return +NUMERAL[s];

    let number = 0;
    for (let i = 0; i < s.length; i++) {
        let num = +NUMERAL[s[i]];
        let prev = +NUMERAL[s[i-1]];

        if (prev < num) number += num - (2 * prev);
        else number += num;
    }

    return number;
};
```