Skip to content

Instantly share code, notes, and snippets.

@iCaspar
Created December 11, 2018 14:51
Show Gist options
  • Save iCaspar/0c161b342bf038ac48f05455b751449f to your computer and use it in GitHub Desktop.
Save iCaspar/0c161b342bf038ac48f05455b751449f to your computer and use it in GitHub Desktop.
A function to convert an aribic (base 10) number to a Roman numeral
function convertToRoman(num) {
const romanSymbols = {
M: 1000,
CM: 900,
D: 500,
CD: 400,
C: 100,
XC: 90,
L: 50,
XL: 40,
X: 10,
IX: 9,
V: 5,
IV: 4,
I: 1
}
let romanNum = ''
for (let romanSymbol in romanSymbols) {
while (num >= romanSymbols[romanSymbol]) {
romanNum += romanSymbol
num -= romanSymbols[romanSymbol]
}
}
return romanNum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment