Created
February 25, 2015 04:43
-
-
Save nicksheffield/aa306d0b8e98aba2b47e to your computer and use it in GitHub Desktop.
Roman numeral to integer converter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function romanToInt(s){ | |
| var n=0,i=0,d={'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000}; | |
| for(;i<s.length;i++)n+=d[s[i+1]]>d[s[i]]?d[s[i]]*-1:d[s[i]]; | |
| return n; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment