-
Notifications
You must be signed in to change notification settings - Fork 22
Open
Description
let romanToNumbers = {
I: 1,
V: 5,
X: 10,
L: 50,
C: 100,
D: 500,
M: 1000
};
let romanToInt = roman => {
let n = 0;
let total = roman.length;
let index = 0;
while (index < total) {
let current = roman[index],
next = roman[index + 1];
let currentValue = romanToNumbers[current];
let nextValue = romanToNumbers[next];
if (currentValue < nextValue) {
n += nextValue - currentValue;
index++;
} else {
n += currentValue;
}
index++;
}
return n;
};Reactions are currently unavailable