This problem is like a puzzle. It's fun for me.
https://leetcode.com/problems/integer-to-roman/
let div = (num) => (num < 10 ? [num] : [num % 10, ...div(~~(num / 10))]);
let times = (s, n) => (n === 1 ? s : s + times(s, n - 1));
let romans = [
["I", "V"],
["X", "L"],
["C", "D"],
["M", ""],
["", ""],
];
let itor = (d, digit) => {
let [one, five] = romans[digit];
let ten = romans[digit + 1][0];
switch (d) {
case 1:
case 2:
case 3:
return times(one, d);
case 4:
return one + five;
case 5:
return five;
case 6:
case 7:
case 8:
return five + times(one, d - 5);
case 9:
return one + ten;
}
return "";
};
var intToRoman = function (num) {
return div(num)
.map((n, i) => itor(n, i))
.reverse()
.join("");
};