{"action":"created","issue":{"url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/issues/28","labels_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/issues/28/labels{/name}","comments_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/issues/28/comments","events_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/issues/28/events","html_url":"https://github.com/JuanitoFatas/fast-ruby/pull/28","id":59095903,"number":28,"title":"Adding Array#reverse.index vs Array#size - Array#index - 1","user":{"login":"theunraveler","id":145273,"avatar_url":"https://avatars.githubusercontent.com/u/145273?v=3","gravatar_id":"","url":"https://api.github.com/users/theunraveler","html_url":"https://github.com/theunraveler","followers_url":"https://api.github.com/users/theunraveler/followers","following_url":"https://api.github.com/users/theunraveler/following{/other_user}","gists_url":"https://api.github.com/users/theunraveler/gists{/gist_id}","starred_url":"https://api.github.com/users/theunraveler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theunraveler/subscriptions","organizations_url":"https://api.github.com/users/theunraveler/orgs","repos_url":"https://api.github.com/users/theunraveler/repos","events_url":"https://api.github.com/users/theunraveler/events{/privacy}","received_events_url":"https://api.github.com/users/theunraveler/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-02-26T16:16:58Z","updated_at":"2015-02-26T16:23:51Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/pulls/28","html_url":"https://github.com/JuanitoFatas/fast-ruby/pull/28","diff_url":"https://github.com/JuanitoFatas/fast-ruby/pull/28.diff","patch_url":"https://github.com/JuanitoFatas/fast-ruby/pull/28.patch"},"body":"The code is a bit uglier and not quite as idiomatic, but I thought the performance improvement may make it work including. The performance gap grows pretty significantly with the size of the array; an array with 100,000,000 items shows the following, for example:\r\n\r\n```\r\nComparison:\r\n              size -:   233724.3 i/s\r\n     reverse + index:        1.3 i/s - 186342.67x slower\r\n```"},"comment":{"url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/issues/comments/76208739","html_url":"https://github.com/JuanitoFatas/fast-ruby/pull/28#issuecomment-76208739","issue_url":"https://api.github.com/repos/JuanitoFatas/fast-ruby/issues/28","id":76208739,"user":{"login":"theunraveler","id":145273,"avatar_url":"https://avatars.githubusercontent.com/u/145273?v=3","gravatar_id":"","url":"https://api.github.com/users/theunraveler","html_url":"https://github.com/theunraveler","followers_url":"https://api.github.com/users/theunraveler/followers","following_url":"https://api.github.com/users/theunraveler/following{/other_user}","gists_url":"https://api.github.com/users/theunraveler/gists{/gist_id}","starred_url":"https://api.github.com/users/theunraveler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theunraveler/subscriptions","organizations_url":"https://api.github.com/users/theunraveler/orgs","repos_url":"https://api.github.com/users/theunraveler/repos","events_url":"https://api.github.com/users/theunraveler/events{/privacy}","received_events_url":"https://api.github.com/users/theunraveler/received_events","type":"User","site_admin":false},"created_at":"2015-02-26T16:23:51Z","updated_at":"2015-02-26T16:23:51Z","body":"Also note that these two implementations only produce the same result if there is only 1 of the item you're looking for in the array. For example:\r\n\r\n```\r\n>> array = [1, 1, 2, 2, 3, 3, 4, 4]\r\n=> [1, 1, 2, 2, 3, 3, 4, 4]\r\n>> array.reverse.index(3)\r\n=> 2\r\n>> array.size - array.index(3) - 1\r\n=> 3\r\n```\r\n\r\nI'll leave it up to you all whether you'd like to make a note of the difference, or not merge the PR because the examples aren't totally congruous."}}