I am experimenting with creating my own method for Romanising numbers and I'm seeking some advice on its feasibility.
Currently, my code returns Null with each iteration. I can't figure out what's causing this issue. Any suggestions would be greatly appreciated!
var array;
var result = [];
function convertToRoman(num) {
array = num.toString().split('').reverse();
roman = ["", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX",
"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC",
"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"
];
for (i = 0, j = 0; i < array.length; i++, j += 10) {
var location = array[i] + j;
result = result.concat(roman[location]);
}
return result.reverse().join();
}
console.log(convertToRoman(123));