I know there are a few different ways to Romanise a number, however I'm trying to make up my own and was wondering if this approach is possible.
It returns Null for every iteration and I can't seem to see what I am missing here. Any help would be much 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));