Ad
Code
Diff
  • var 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 = {
    • "I": 1,
    • "V": 5,
    • "X": 10,
    • "L": 50,
    • "C": 100,
    • "D": 500,
    • "M": 1000
    • }
    • function solution (roman) {
    • letters = roman.split('');
    • var res = 0;
    • letters.forEach((cur, i) => {
    • var next = letters[i + 1];
    • if (tr[next] && tr[cur] < tr[next]) {
    • res -= tr[cur];
    • } else {
    • res += tr[cur];
    • }
    • })
    • return res;
    • 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);
    • }