Guest User

Untitled

a guest
Dec 14th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. function* romanSequence (from, to) {
  2. switch (arguments.length) {
  3. case 0:
  4. console.warn('[romanNumerals]: the function expects at least one argument')
  5. return
  6. case 1:
  7. to = from
  8. from = 1
  9. }
  10.  
  11. const key = [
  12. "", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM",
  13. "", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC",
  14. "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"
  15. ]
  16.  
  17. for (; from <= to; from++) {
  18. const digits = String(from).split("")
  19.  
  20. let i = 3
  21. let roman = ""
  22.  
  23. while (i--)
  24. roman = (key[+digits.pop() + (i * 10)] || "") + roman
  25.  
  26. yield Array(+digits.join("") + 1).join("M") + roman
  27. }
  28. }
Add Comment
Please, Sign In to add comment