There was an error while loading. Please reload this page.
1 parent d6c48ae commit 1ca4dadCopy full SHA for 1ca4dad
.vscode/settings.json
@@ -1,3 +1,3 @@
1
{
2
- "cSpell.words": ["Palindrom"]
+ "cSpell.words": ["MCMXCIV", "Palindrom"]
3
}
13-romatToInt.js
@@ -0,0 +1,23 @@
+const romanToInt = (s) => {
+ const roman = {
+ I: 1,
4
+ V: 5,
5
+ X: 10,
6
+ L: 50,
7
+ C: 100,
8
+ D: 500,
9
+ M: 1000,
10
+ };
11
+ let sum = 0;
12
+ for (let i = 0; i < s.length; i++) {
13
+ if (roman[s[i]] < roman[s[i + 1]]) {
14
+ sum += roman[s[i + 1]] - roman[s[i]];
15
+ i++;
16
+ } else {
17
+ sum += roman[s[i]];
18
+ }
19
20
+ return sum;
21
+};
22
+
23
+console.log(romanToInt('MCMXCIV'));
0 commit comments