Created
January 16, 2024 18:53
-
-
Save berdfandrade/da001dd997705f055ccb6f5310c430ab to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function convertToRoman(num) { | |
let resultado = ""; | |
const array = { | |
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 | |
}; | |
for (let i in array) { | |
while (num >= array[i]) { | |
resultado = resultado + i; | |
num = num - array[i]; | |
} | |
} | |
return resultado; | |
} | |
console.log(convertToRoman(36)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment