Roman numerals to integer
MediumStrings · JavaScript
The task
Write romanToInt(s) that converts a Roman numeral to an integer.
The symbols are I=1, V=5, X=10, L=50, C=100, D=500 and M=1000. When a smaller symbol comes before a larger one, it is subtracted, as in IV = 4 and IX = 9.
Examples
- romanToInt("III") returns 3
- romanToInt("MCMXCIV") returns 1994
Your code runs in your browser, in a separate worker, and is never sent to us. Edit the function, then press Run tests. Your work is saved here as you type.
JavaScriptCtrl or Cmd + Enter to run