Created
February 3, 2019 22:38
-
-
Save kolektiv/96797f33e7c910c1ecb7da6af084cf14 to your computer and use it in GitHub Desktop.
Roman Numerals
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 conversions = [ | |
[1000, 'M'], | |
[900, 'CM'], | |
[500, 'D'], | |
[400, 'CD'], | |
[100, 'C'], | |
[90, 'XC'], | |
[50, 'L'], | |
[40, 'XL'], | |
[10, 'X'], | |
[9, 'IX'], | |
[5, 'V'], | |
[4, 'IV'], | |
[1, 'I'] | |
]; | |
const convert = (arabian) => ( | |
conversions.reduce(([ roman, arabian ], [ value, text ]) => ( | |
[ roman + text.repeat(arabian / value), arabian % value ] | |
), [ '', arabian ])[0] | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment