Skip to content

Instantly share code, notes, and snippets.

@wisetara
Created August 23, 2017 06:24
Show Gist options
  • Save wisetara/b6fe148572edb0d826668ed33fd27933 to your computer and use it in GitHub Desktop.
Save wisetara/b6fe148572edb0d826668ed33fd27933 to your computer and use it in GitHub Desktop.
Convert Arabic Numbers to Roman Numerals
var romanNumbers = [['','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']];
function convert(number) {
var romanNumeral = '';
var reversedNumber = number.toString().split('').reverse();
for (var i=0; i < digits.length; i++){
romanNumeral = romanNumbers[i][parseInt(reversedNumber[i])] + romanNumeral;
}
return romanNumeral;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment