So, the solution I thought up for this challenge was to get two arrays (one with the Roman Numerals and the other with the Decimals), join key:value together and then just look up the “num” variable. It works, but, of course, it only works if I get every value possible in both arrays which seems to go agaisnt the nature of the challenge (not to mention agaisnt any actual functionality). Any ideas on how I could improve it?
var arrRoman=["I","IV","V","IX","X","XL","L","C","D","M"];
var arrNumbers=[1,4,5,9,10,40,50,100,500,1000];
var comparison= {};
for (var i = 0; i < arrRoman.length; i++)
comparison[arrNumbers[i]] = arrRoman[i];
return (comparison[num]);
}
convertToRoman(36);