const tr = { "I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000 } function solution (roman_string) { return roman_string.split('').map((letter, index, a) => { const current_value = tr[letter]; const next_value = tr[a[index+1]]; return next_value && current_value < next_value ? (- current_value) : current_value; }).reduce((acc, item) => acc + item, 0); }
var tr = {- const tr = {
- "I": 1,
- "V": 5,
- "X": 10,
- "L": 50,
- "C": 100,
- "D": 500,
- "M": 1000
- }
- function solution (roman_string) {
- return roman_string.split('').map((letter, index, a) => {
- const current_value = tr[letter];
- const next_value = tr[a[index+1]];
- return next_value && current_value < next_value ?
- (- current_value) : current_value;
- }).reduce((acc, item) => acc + item, 0);
- }