Skip to content

Instantly share code, notes, and snippets.

@pixshatterer
Created August 6, 2014 18:30
Show Gist options
  • Select an option

  • Save pixshatterer/340c4140eed6f39925c1 to your computer and use it in GitHub Desktop.

Select an option

Save pixshatterer/340c4140eed6f39925c1 to your computer and use it in GitHub Desktop.
EXAMINE THIS
parseMolecule=function x(f,r){
for(r=1;r;)
r=0,f=f.replace(/\W(([A-Z][a-z]*\d*)*)[)\]}](\d*)/g,function(m,g,_,c){
_='';for(r in m=x(g))_+=r+m[r]*(c||1);return _
})
for(r={},m=/(\w[a-z]*)(\d*)/g;a=m.exec(f);r[c]+=+a[2]||1)
r[c=a[1]]|=0
return r
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment