const roman = {
'I' : 1,
'V' : 5,
'X' : 10,
'L' : 50,
'C' : 100,
'D' : 500,
'M' : 1000,
}
const romanToNum = s => {
let arr = s.split("");
let result = arr.reduce((acc, val, idx) => {
let curVal = roman[val];
let nextVal = roman[arr[idx + 1]];
if (curVal < nextVal) {
acc -= curVal
} else {
acc += curVal
}
return acc;
}, 0)
return result;
}