Created
April 23, 2019 10:37
-
-
Save evadav/8d18ba75d6da4dfb8cb1fe18053cf911 to your computer and use it in GitHub Desktop.
Convertir a números romanos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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