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.
romanNumerals in js
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment