Skip to content

Instantly share code, notes, and snippets.

@qntm
Last active June 17, 2019 19:50
Show Gist options
  • Save qntm/3d2c3977ee04ead226590299bffa6545 to your computer and use it in GitHub Desktop.
Save qntm/3d2c3977ee04ead226590299bffa6545 to your computer and use it in GitHub Desktop.
An extremely spare Roman numerals converter
// 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