Skip to content

Instantly share code, notes, and snippets.

@evadav
Created April 23, 2019 10:37
Show Gist options
  • Save evadav/8d18ba75d6da4dfb8cb1fe18053cf911 to your computer and use it in GitHub Desktop.
Save evadav/8d18ba75d6da4dfb8cb1fe18053cf911 to your computer and use it in GitHub Desktop.
Convertir a números romanos
module.exports = function romanToArabic (num){
let romans = {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 letter=''
let resultado= ''
let valor = 0
for (letter in romans ){
valor = romans[letter]
while (num >= valor){
resultado += letter
num -= valor
}
}
return resultado;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment