I am eager to develop a Javascript Algorithm that can convert Roman numerals to Arabic using the provided methods below.
I have managed to find an algorithm that accomplishes this task successfully.
function convertToRoman(num) {
var numeric = [ 5000,4000,1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 ];
var roman = [ 'V\u0305','I\u0305V\u0305','M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I' ];
var output = '', i, len = numeric.length;
for (i = 0; i < len; i++) {
while (numeric[i] <= num) {
output += roman[i];
num -= numeric[i];
}
}
return output;
}
convertToRoman(4999);
However, I am interested in learning how to implement an algorithm using the suggested methods above.
Thank you, and please be patient with me as I am still a beginner programmer.