Portfolio-v3/components/romanNumerals.js
Robert S 79cc0cb8d1
Layout function o.O
Cleaned up the code and that's about it.
2021-12-10 23:09:37 +01:00

13 lines
No EOL
519 B
JavaScript

export default function RomanNumerals(num) {
if (isNaN(num))
return NaN;
let digits = String(+num).split(""),
key = ["", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM",
"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC",
"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"],
roman = "",
i = 3;
while (i--)
roman = (key[+digits.pop() + (i * 10)] || "") + roman;
return Array(+digits.join("") + 1).join("M") + roman;
}