I want to implement Algorithm which converts Roman numeral to Arabic with Javascript. Using the following suggested methods.
I have already found the algorithm which solves this task
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);
Nevertheless i'm curious how to implement an algorithm with above mentioned methods.
Thanks, please do not judge me harshly, i'm a beginner programmer.