Roman Numeral Converter feedback request: ridiculous object + couple lines of code gets the job done

Ok, I will definitely rewrite this solution, because it’s too straightforward, and there is definitely a pattern in terms of decimal to roman convertion which can be used.
But I wanted to play around accessing object props(like in record collection step from Basic JS), and apparently it was enough to pass :upside_down_face:

function convertToRoman(num) {

    const romanDictionary = {
  
        0 : {
          
          0: '',
          1: 'I',
          2: 'II',
          3: 'III',
          4: 'IV',
          5: 'V',
          6: 'VI',
          7: 'VII',
          8: 'VIII',
          9: 'IX'
          
        },
        
        1 : {
          
          0: '',
          1: 'X',
          2: 'XX',
          3: 'XXX',
          4: 'XL',
          5: 'L',
          6: 'LX',
          7: 'LXX',
          8: 'LXX',
          9: 'LC'
          
        },
        
        2 : {
          
          0: '',
          1: 'C',
          2: 'CC',
          3: 'CCC',
          4: 'CD',
          5: 'D',
          6: 'DC',
          7: 'DCC',
          8: 'DCCC',
          9: 'CM'
          
        },
        
        3 : {
          
          0: '',
          1: 'M',
          2: 'MM',
          3: 'MMM'
          
        }
      }

      formattedNumber = String(number).split("").reverse();//4321 >>> ['1', '2', '3', '4']

      return formattedNumber.map(
        (digit, index) => romanDictionary[index][digit]
        ).reverse().join('')
 
}

You seem to ask for review for many of the challenges you complete. Have you tried looking at the Guide solutions? They should give you other ideas about how the challenge can be approached. Then, it is just a matter of comparing yours to the others.

If you have a specific question about one of your solutions, that is fine. Otherwise, it feels kind of like “Here’s my solution”. Historically, we don’t allow those types of topics on the forum.

1 Like

Makes sense.
Here I have question. To build object like this if we are solving similar problem(conversion of some kind): this is a good approach in general or not?

I tend to use object lookups for solutions for many things. I personally approached this challenge differently, but using the object in this case is better than some solutions I have seen posted.

FYI - Instead of reversing and then reversing again, you might take a look at:

Array.prototype.reduceRight()

Good point, thanks.

I guess I can avoid reversing by slightly changing object structure also.