functionsolution(number){// todo: solve without defining middle values :(vartranslations={'M':1000,'CM':900,'D':500,'CD':400,'C':100,'XC':90,'L':50,'XL':40,'X':10,'IX':9,'V':5,'IV':4,'I':1};varanswer='';varvalue=0;varthisPower=0;Object.keys(translations).forEach(function(letter,index,array){thisPower=translations[letter];value=Math.floor(number/thisPower);number-=value*thisPower;answer+=letter.repeat(value);});returnanswer;}
Mine works... but I every time I tried doing something clever to not have to define 900, 400, 90, 40, and 9, it wouldn't work on 4, so I gave up on that. I really liked the .repeat so I didn't have to define multiples, though.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Mine works... but I every time I tried doing something clever to not have to define 900, 400, 90, 40, and 9, it wouldn't work on 4, so I gave up on that. I really liked the .repeat so I didn't have to define multiples, though.