Created
April 8, 2021 08:49
-
-
Save antonydenyer/51bf0d06943a874da99baf955a8db942 to your computer and use it in GitHub Desktop.
romanNumerals in js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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