Last active
June 17, 2019 19:50
-
-
Save qntm/3d2c3977ee04ead226590299bffa6545 to your computer and use it in GitHub Desktop.
An extremely spare Roman numerals converter
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
// No bounds/type checking | |
// No support for the overbar extension for numbers past 3999 | |
const banks = [ | |
['', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'], | |
['', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC'], | |
['', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM'], | |
['', 'M', 'MM', 'MMM'] | |
] | |
export default number => number | |
.toString() | |
.split('') | |
.map((digit, i, digits) => banks[digits.length - i - 1][digit]) | |
.join('') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment