https://leetcode.com/problems/roman-to-integer/
I parsed Roman ex)IXIV
to Integer ex)94
in this problem.
let alphas = ["I", "V", "X", "L", "C", "D", "M", "", ""];
/**
* @param {string} s
* @return {number}
*/
var romanToInt = function (s) {
let sum = 0;
for (let i = 0; i < s.length; i++) {
let c = s[i];
let ci = alphas.findIndex((a) => a === c);
if (ci % 2) {
sum += 5 * Math.pow(10, (ci - 1) / 2);
continue;
}
let tens = Math.pow(10, ci / 2);
let nc = s[i + 1];
if (nc === alphas[ci + 1]) {
sum += 4 * tens;
i++;
continue;
}
if (nc === alphas[ci + 2]) {
sum += 9 * tens;
i++;
continue;
}
if (nc === c) {
if (s[i + 2] === c) {
sum += 3 * tens;
i += 2;
continue;
}
sum += 2 * tens;
i++;
continue;
}
sum += tens;
}
return sum;
};