var romanToInt = function(s) {
const roman_map = {'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000};
let result = 0;
for (var i=0;i<s.length;i++) {
const cur = roman_map[s[i]];
const next = roman_map[s[i+1]];
if (cur<next) {
result += next-cur;
i++
} else {
result += cur
}
}
return result
};