Roman Numeral Project Feedback

Could I have feedback on my Roman Numerals project. My first passing tests were awfully repetitive. For my second rewrite I stored the values in an object and used them in place of the values, but did not change much logic. This time I rewrote the logic to hopefully make it cleaner. Is there any way I could further improve this?

Also will it eventually update on my profile since it passed the test or do I have to put it on a different page? UPDATE: Its now showing after a bit.

function convertToRoman(num) {
  let n = num; // Keeps num constant
    let roman = ""; // Final output

 const romanNums = { // Stores the key values pairs of Roman Numerals
    "1": "I",
    "4": "IV",
    "5": "V",
    "9": "IX",
    "10": "X",
    "40": "XL",
    "50": "L",
    "90": "XC",
    "100": "C",
    "400": "CD",
    "500": "D",
    "900": "CM",
    "1000": "M"
  }
  for (const [key, value] of Object.entries(romanNums).reverse()) { 
    while (n >= key) {
      n -= key;
      roman += value;
    }
  }
 console.log(roman)
  return roman
}

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.