将给定的数字转换成罗马数字。
所有返回的 罗马数字 都应该是大写形式。
这是一些对你有帮助的资源:
function convertToRoman(num) { var nums =[1000,900,500,400,100,90,50,40, 10, 9, 5, 4, 3, 2, 1]; var romans = ["M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","III","II", "I"]; var result =''; nums.forEach((item,index)=>{ while(item<=num){ result += romans[index]; num -= nums[index]; } }) return result; }