{"action":"created","issue":{"url":"https://api.github.com/repos/liuguanyu/quiz-every-meeting/issues/8","repository_url":"https://api.github.com/repos/liuguanyu/quiz-every-meeting","labels_url":"https://api.github.com/repos/liuguanyu/quiz-every-meeting/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/liuguanyu/quiz-every-meeting/issues/8/comments","events_url":"https://api.github.com/repos/liuguanyu/quiz-every-meeting/issues/8/events","html_url":"https://github.com/liuguanyu/quiz-every-meeting/issues/8","id":325562319,"number":8,"title":"解析化学分子式中各个原子的个数","user":{"login":"Kate605690919","id":23615318,"avatar_url":"https://avatars3.githubusercontent.com/u/23615318?v=4","gravatar_id":"","url":"https://api.github.com/users/Kate605690919","html_url":"https://github.com/Kate605690919","followers_url":"https://api.github.com/users/Kate605690919/followers","following_url":"https://api.github.com/users/Kate605690919/following{/other_user}","gists_url":"https://api.github.com/users/Kate605690919/gists{/gist_id}","starred_url":"https://api.github.com/users/Kate605690919/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kate605690919/subscriptions","organizations_url":"https://api.github.com/users/Kate605690919/orgs","repos_url":"https://api.github.com/users/Kate605690919/repos","events_url":"https://api.github.com/users/Kate605690919/events{/privacy}","received_events_url":"https://api.github.com/users/Kate605690919/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-05-23T06:14:05Z","updated_at":"2018-05-28T17:27:56Z","closed_at":null,"author_association":"NONE","body":"## 解析化学分子式中各个原子的个数\r\n**题目描述**\r\n完成函数parseMolecule()，解析任意形式的化学分子表达式，返回结果为一个对象\r\n\r\n**示例**\r\n注：该示例中未给出含有大括号{}的分子式，编写算法时应考虑到\r\n\r\nvar water = 'H2O';\r\nparseMolecule(water); // return {H: 2, O: 1}\r\n\r\nvar magnesiumHydroxide = 'Mg(OH)2';\r\nparseMolecule(magnesiumHydroxide); // return {Mg: 1, O: 2, H: 2}\r\n\r\nvar fremySalt = 'K4[ON(SO3)2]2';\r\nparseMolecule(fremySalt); // return {K: 4, O: 14, N: 2, S: 4}"},"comment":{"url":"https://api.github.com/repos/liuguanyu/quiz-every-meeting/issues/comments/392574769","html_url":"https://github.com/liuguanyu/quiz-every-meeting/issues/8#issuecomment-392574769","issue_url":"https://api.github.com/repos/liuguanyu/quiz-every-meeting/issues/8","id":392574769,"user":{"login":"Kate605690919","id":23615318,"avatar_url":"https://avatars3.githubusercontent.com/u/23615318?v=4","gravatar_id":"","url":"https://api.github.com/users/Kate605690919","html_url":"https://github.com/Kate605690919","followers_url":"https://api.github.com/users/Kate605690919/followers","following_url":"https://api.github.com/users/Kate605690919/following{/other_user}","gists_url":"https://api.github.com/users/Kate605690919/gists{/gist_id}","starred_url":"https://api.github.com/users/Kate605690919/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kate605690919/subscriptions","organizations_url":"https://api.github.com/users/Kate605690919/orgs","repos_url":"https://api.github.com/users/Kate605690919/repos","events_url":"https://api.github.com/users/Kate605690919/events{/privacy}","received_events_url":"https://api.github.com/users/Kate605690919/received_events","type":"User","site_admin":false},"created_at":"2018-05-28T17:27:56Z","updated_at":"2018-05-28T17:27:56Z","author_association":"NONE","body":"发一个参考答案\r\n```js\r\nfunction parseMolecule(formula) {\r\n    var r1=/\\((\\w+)\\)(\\d{0,})/g;  //匹配小括号及后面可能出现的任意位数的数字\r\n    var r2=/\\[(\\w+)\\](\\d{0,})/g;  //匹配中括号及后面可能出现的任意位数的数字\r\n    var r3=/\\{(\\w+)\\}(\\d{0,})/g;  //匹配大括号及后面可能出现的任意位数的数字\r\n\r\n    var formula = formula.replace(r1,repeat).replace(r2,repeat).replace(r3,repeat);//括号去掉完毕\r\n    console.log(formula);\r\n    var c_num=formula.match(/[A-Z][a-z]?\\d{0,}/g);//输出类似[ 'K4', 'O', 'N', 'S', 'O3'， 'S']形式数组\r\n    var res={}; //定义一个用来存储结果的对象\r\n    c_num.forEach(function(c){\r\n        var _c=c.match(/[A-Z][a-z]/)?c.split(\"\")[0]+c.split(\"\")[1]:c.split(\"\")[0];//判断元素是否存在小写字母\r\n        var num=c.match(/[0-9]$/)?parseInt(/\\d+/.exec(c)[0]):1;//如果元素符号后存在数字则存入相应数字，否则存入1\r\n        res[_c]=(res[_c]||0)+num;\r\n    });\r\n    return(res);\r\n}\r\nfunction repeat(m,p1,p2) {   //定义一个去掉括号的函数，在replace方法中回掉\r\n    p2=parseInt(p2)-1;\r\n    for(var temp=p1;p2--;temp+=p1);\r\n    return temp;\r\n}\r\n```"}}
{"actor":{"display_login":"Kate605690919"}}