DEV Community

Discussion on: Daily Challenge #209 - Roman Numerals

Collapse
 
davidcoroian profile image
David
const mapRomanNToN = {
  'I': 1,
  'V': 5,
  'X': 10,
  'L': 50,
  'C': 100,
  'D': 500,
  'M': 1000,
}

const solution = (str) => {
  const reducer = (acc, curVal) => {
    return acc += mapRomanNToN[curVal];
  }

  return str.split('').reduce(reducer, 0);
}
Collapse
 
sabbin profile image
Sabin Pandelovitch • Edited

Not working, due to the fact that you ignored that if a value is smaller than the next one it's substracted not added... check the test case MCMXC it should be 1990 and yours is 2210

Collapse
 
davidcoroian profile image
David

haha you re right! thanks. Was in a rush. will fix it