Draft
Roman numeral decoder with format validator
35RaRaton
Description:
Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You need to validate the form of the Roman numeral.
The function must return -1, if roman number is not well formatted.
A well formatted roman number meet the next rules:
- Roman number are based on seven symbols: I, V, X, L, C, D, M, and their decimal values are 1, 5, 10, 50, 100, 500, 1000
- Generally, symbols are placed in order of value, starting with the largest values. When smaller values precede larger values, the smaller values are subtracted from the larger values, and the result is added to the total. For example MCMXLIV = 1000 + (1000 - 100) + (50 - 10) + (5 - 1) = 1944.
- The symbols "I", "X", "C", and "M" can be repeated three times in succession, but no more. (They may appear four times if the third and fourth are separated by a smaller value, such as XXXIX.) "D", "L", and "V" can never be repeated.
- "I" can be subtracted from "V" and "X" only. "X" can be subtracted from "L" and "C" only. "C" can be subtracted from "D" and "M" only. "V", "L", and "D" can never be subtracted.
- Only one small-value symbol may be subtracted from any large-value symbol.
Example:
convertRomanToDecimal('XXI'); // should return 21
convertRomanToDecimal('DCCCXXLX'); // should return -1 because wrong format
Note:
There is a Kata that cover the validation process of Roman numerals:https://www.codewars.com/kata/58334362c5637ad0bb0001c2
There is a Kata that cover the conversion of Roman numerals to decimal:
https://www.codewars.com/kata/roman-numerals-decoder/javascript
Algorithms
Parsing
Strings
Regular Expressions
Fundamentals
Similar Kata:
Stats:
Created | Nov 29, 2016 |
Warriors Trained | 192 |
Total Skips | 29 |
Total Code Submissions | 195 |
Total Times Completed | 35 |
JavaScript Completions | 35 |
Total Stars | 6 |
% of votes with a positive feedback rating | 72% of 16 |
Total "Very Satisfied" Votes | 11 |
Total "Somewhat Satisfied" Votes | 1 |
Total "Not Satisfied" Votes | 4 |
Total Rank Assessments | 11 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 7 kyu |