Roman Numerals Both Ways
Medium · Parsing
Write convertRoman(input: string | number): string | number | null.
- For a number: return its Roman numeral if it is an integer from 1 to 3999, otherwise null. Use the standard subtractive forms (IV, IX, XL, XC, CD, CM).
- For a string: return its value if it is a VALID numeral in the standard form (upper-case, exactly what converting the value back would produce), otherwise null. So "IIII", "IC", "VX", "MMMM", "" and "xii" are all invalid.
Tip: parse the string, then convert the result back and compare.
Next: Deep Merge