Skip to content

Instantly share code, notes, and snippets.

@kolektiv
Created February 3, 2019 22:38
Show Gist options
  • Save kolektiv/96797f33e7c910c1ecb7da6af084cf14 to your computer and use it in GitHub Desktop.
Save kolektiv/96797f33e7c910c1ecb7da6af084cf14 to your computer and use it in GitHub Desktop.
Roman Numerals
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