Skip to content

Instantly share code, notes, and snippets.

@nicksheffield
Created February 25, 2015 04:43
Show Gist options
  • Select an option

  • Save nicksheffield/aa306d0b8e98aba2b47e to your computer and use it in GitHub Desktop.

Select an option

Save nicksheffield/aa306d0b8e98aba2b47e to your computer and use it in GitHub Desktop.
Roman numeral to integer converter
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