We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2290339 commit 03535e8Copy full SHA for 03535e8
13-roman-to-integer.js
@@ -0,0 +1,30 @@
1
+/**
2
+ * @param {string} s
3
+ * @return {number}
4
+ */
5
+var romanToInt = function(s) {
6
+ const romanMap = {
7
+ 'I': 1,
8
+ 'V': 5,
9
+ 'X': 10,
10
+ 'L': 50,
11
+ 'C': 100,
12
+ 'D': 500,
13
+ 'M': 1000
14
+ }
15
+
16
+ let total = 0;
17
18
+ for (let i = 0; i < s.length; i++) {
19
+ const currValue = romanMap[s[i]];
20
+ const nextValue = romanMap[s[i + 1]];
21
22
+ if (currValue < nextValue) {
23
+ total -= currValue;
24
+ } else {
25
+ total += currValue;
26
27
28
29
+ return total;
30
+};
0 commit comments