Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function* romanSequence (from, to) {
- switch (arguments.length) {
- case 0:
- console.warn('[romanNumerals]: the function expects at least one argument')
- return
- case 1:
- to = from
- from = 1
- }
- const 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"
- ]
- for (; from <= to; from++) {
- const digits = String(from).split("")
- let i = 3
- let roman = ""
- while (i--)
- roman = (key[+digits.pop() + (i * 10)] || "") + roman
- yield Array(+digits.join("") + 1).join("M") + roman
- }
- }
Add Comment
Please, Sign In to add comment