{"action":"created","issue":{"url":"https://api.github.com/repos/maranran/leetcode/issues/4","repository_url":"https://api.github.com/repos/maranran/leetcode","labels_url":"https://api.github.com/repos/maranran/leetcode/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/maranran/leetcode/issues/4/comments","events_url":"https://api.github.com/repos/maranran/leetcode/issues/4/events","html_url":"https://github.com/maranran/leetcode/issues/4","id":338187859,"node_id":"MDU6SXNzdWUzMzgxODc4NTk=","number":4,"title":"罗马数字转整数","user":{"login":"maranran","id":6880954,"node_id":"MDQ6VXNlcjY4ODA5NTQ=","avatar_url":"https://avatars0.githubusercontent.com/u/6880954?v=4","gravatar_id":"","url":"https://api.github.com/users/maranran","html_url":"https://github.com/maranran","followers_url":"https://api.github.com/users/maranran/followers","following_url":"https://api.github.com/users/maranran/following{/other_user}","gists_url":"https://api.github.com/users/maranran/gists{/gist_id}","starred_url":"https://api.github.com/users/maranran/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maranran/subscriptions","organizations_url":"https://api.github.com/users/maranran/orgs","repos_url":"https://api.github.com/users/maranran/repos","events_url":"https://api.github.com/users/maranran/events{/privacy}","received_events_url":"https://api.github.com/users/maranran/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-04T08:56:57Z","updated_at":"2018-07-04T10:23:46Z","closed_at":null,"author_association":"OWNER","body":"```\r\nlet maps = {\r\n  'I': 1,\r\n  'V': 5,\r\n  'X': 10,\r\n  'L': 50,\r\n  'C': 100,\r\n  'D': 500,\r\n  'M': 1000,\r\n  'IV': 4,\r\n  'IX': 9,\r\n  'XL': 40,\r\n  'XC': 90,\r\n  'CD': 400,\r\n  'CM': 900\r\n}\r\n\r\n/**\r\n* @param {string}\r\n* @return {number}\r\n*/\r\nfunction StrtoNums(str) {\r\n  let map =  /(X[LC])|(I[VX])|(C[DM])|[IVXLCDM]/g  // 注意：g的使用使得 match返回 一个包含所有匹配的元素的数组 \r\n  let keys = str.match(map) // 返回拆分后的匹配的各个key\r\n  let resulut = keys.reduce(function(accumulator, currentValue){\r\n    return maps[currentValue] + accumulator\r\n  }, 0)  //  第二个参数为accumulator的初始值\r\n  console.log(resulut)\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/maranran/leetcode/issues/comments/402436609","html_url":"https://github.com/maranran/leetcode/issues/4#issuecomment-402436609","issue_url":"https://api.github.com/repos/maranran/leetcode/issues/4","id":402436609,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMjQzNjYwOQ==","user":{"login":"maranran","id":6880954,"node_id":"MDQ6VXNlcjY4ODA5NTQ=","avatar_url":"https://avatars0.githubusercontent.com/u/6880954?v=4","gravatar_id":"","url":"https://api.github.com/users/maranran","html_url":"https://github.com/maranran","followers_url":"https://api.github.com/users/maranran/followers","following_url":"https://api.github.com/users/maranran/following{/other_user}","gists_url":"https://api.github.com/users/maranran/gists{/gist_id}","starred_url":"https://api.github.com/users/maranran/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maranran/subscriptions","organizations_url":"https://api.github.com/users/maranran/orgs","repos_url":"https://api.github.com/users/maranran/repos","events_url":"https://api.github.com/users/maranran/events{/privacy}","received_events_url":"https://api.github.com/users/maranran/received_events","type":"User","site_admin":false},"created_at":"2018-07-04T10:23:46Z","updated_at":"2018-07-04T10:23:46Z","author_association":"OWNER","body":"```\r\nfunction StrtoNums(str) {\r\n  let mapArray = []\r\n  let max = str.length - 1;\r\n  for(let i = 0 ; i < max; i++) {\r\n    if(maps[str[i]] >= maps[str[i+1]]) {\r\n      mapArray.push(maps[str[i]])\r\n    } else {\r\n      mapArray.push(-maps[str[i]])\r\n    }\r\n  }\r\n  mapArray.push(str[max])\r\n  let resulut = mapArray.reduce(function(accumulator, currentValue){\r\n    return currentValue + accumulator\r\n  }, 0);\r\n  console.log(resulut)\r\n}\r\n```"}}
{"actor":{"display_login":"maranran"}}