{"action":"created","issue":{"url":"https://api.github.com/repos/ckinmind/JS-Algorithm/issues/9","repository_url":"https://api.github.com/repos/ckinmind/JS-Algorithm","labels_url":"https://api.github.com/repos/ckinmind/JS-Algorithm/issues/9/labels{/name}","comments_url":"https://api.github.com/repos/ckinmind/JS-Algorithm/issues/9/comments","events_url":"https://api.github.com/repos/ckinmind/JS-Algorithm/issues/9/events","html_url":"https://github.com/ckinmind/JS-Algorithm/issues/9","id":191864225,"number":9,"title":"中划线连接单词","user":{"login":"ckinmind","id":8199343,"avatar_url":"https://avatars.githubusercontent.com/u/8199343?v=3","gravatar_id":"","url":"https://api.github.com/users/ckinmind","html_url":"https://github.com/ckinmind","followers_url":"https://api.github.com/users/ckinmind/followers","following_url":"https://api.github.com/users/ckinmind/following{/other_user}","gists_url":"https://api.github.com/users/ckinmind/gists{/gist_id}","starred_url":"https://api.github.com/users/ckinmind/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ckinmind/subscriptions","organizations_url":"https://api.github.com/users/ckinmind/orgs","repos_url":"https://api.github.com/users/ckinmind/repos","events_url":"https://api.github.com/users/ckinmind/events{/privacy}","received_events_url":"https://api.github.com/users/ckinmind/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-11-27T14:28:06Z","updated_at":"2016-11-27T14:33:08Z","closed_at":null,"body":"题目来自[FCC:Spinal Tap Case](https://www.freecodecamp.com/challenges/spinal-tap-case),题目要求将单词间的空格下划线转为中划线连接单词，还有可能单词和单词之间无间隔\r\n测试用例主要有：\r\n```js\r\nspinalCase(\"This Is Spinal Tap\") should return \"this-is-spinal-tap\"\r\nspinalCase(\"thisIsSpinalTap\") should return \"this-is-spinal-tap\"\r\nspinalCase(\"The_Andy_Griffith_Show\") should return \"the-andy-griffith-show\"\r\n```"},"comment":{"url":"https://api.github.com/repos/ckinmind/JS-Algorithm/issues/comments/263125504","html_url":"https://github.com/ckinmind/JS-Algorithm/issues/9#issuecomment-263125504","issue_url":"https://api.github.com/repos/ckinmind/JS-Algorithm/issues/9","id":263125504,"user":{"login":"ckinmind","id":8199343,"avatar_url":"https://avatars.githubusercontent.com/u/8199343?v=3","gravatar_id":"","url":"https://api.github.com/users/ckinmind","html_url":"https://github.com/ckinmind","followers_url":"https://api.github.com/users/ckinmind/followers","following_url":"https://api.github.com/users/ckinmind/following{/other_user}","gists_url":"https://api.github.com/users/ckinmind/gists{/gist_id}","starred_url":"https://api.github.com/users/ckinmind/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ckinmind/subscriptions","organizations_url":"https://api.github.com/users/ckinmind/orgs","repos_url":"https://api.github.com/users/ckinmind/repos","events_url":"https://api.github.com/users/ckinmind/events{/privacy}","received_events_url":"https://api.github.com/users/ckinmind/received_events","type":"User","site_admin":false},"created_at":"2016-11-27T14:33:08Z","updated_at":"2016-11-27T14:33:08Z","body":"我的答案：\r\n```js\r\n\r\nfunction spinalCase(str) {\r\n \r\n  return str.replace(/(?=[A-Z])|( +)|_/g,'-').replace(/-{2}/g,'-').replace(/^-/,'').toLowerCase();\r\n}\r\n\r\nspinalCase('thisIsSpinalTap');\r\n```\r\n用了三个replace\r\n>1. 第一个replace会将空格或者下划线转化为中划线，同时将`thisIsSpinalTap`类型转为`-this-Is-Spinal-Tap`, 将`This Is Spinal Tap` `-This--Is--Spinal--Tap`\r\n>2. 第二个和replace就是为了将第一步中两个处理掉\r\n>3. 暂时没想到更好的正则处理"}}
{"actor":{"display_login":"ckinmind"}}