Skip to content

Instantly share code, notes, and snippets.

@antonydenyer
Created April 8, 2021 08:49
Show Gist options
  • Save antonydenyer/51bf0d06943a874da99baf955a8db942 to your computer and use it in GitHub Desktop.
Save antonydenyer/51bf0d06943a874da99baf955a8db942 to your computer and use it in GitHub Desktop.

Revisions

  1. antonydenyer created this gist Apr 8, 2021.
    18 changes: 18 additions & 0 deletions toRoman.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    const toRoman = (numeral) =>
    new Array(numeral + 1)
    .join('I')
    .replaceAll('IIIII', 'V')
    .replaceAll('VV', 'X')
    .replaceAll('XXXXX', 'L')
    .replaceAll('LL', 'C')
    .replaceAll('CCCCC', 'D')
    .replaceAll('DD', 'M')
    .replaceAll('IIII', 'IV')
    .replaceAll('VIV', 'IX')
    .replaceAll('XXXX', 'XL')
    .replaceAll('LXL', 'XC')
    .replaceAll('CCCC', 'CD')
    .replaceAll('DCD', 'CM');

    toRoman(2020);
    toRoman(1999);