{"action":"closed","issue":{"url":"https://api.github.com/repos/andrewplummer/Sugar/issues/471","repository_url":"https://api.github.com/repos/andrewplummer/Sugar","labels_url":"https://api.github.com/repos/andrewplummer/Sugar/issues/471/labels{/name}","comments_url":"https://api.github.com/repos/andrewplummer/Sugar/issues/471/comments","events_url":"https://api.github.com/repos/andrewplummer/Sugar/issues/471/events","html_url":"https://github.com/andrewplummer/Sugar/issues/471","id":47274079,"number":471,"title":"Array creator method that accepts a per-element construction function","user":{"login":"lolmaus","id":200884,"avatar_url":"https://avatars.githubusercontent.com/u/200884?v=3","gravatar_id":"","url":"https://api.github.com/users/lolmaus","html_url":"https://github.com/lolmaus","followers_url":"https://api.github.com/users/lolmaus/followers","following_url":"https://api.github.com/users/lolmaus/following{/other_user}","gists_url":"https://api.github.com/users/lolmaus/gists{/gist_id}","starred_url":"https://api.github.com/users/lolmaus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lolmaus/subscriptions","organizations_url":"https://api.github.com/users/lolmaus/orgs","repos_url":"https://api.github.com/users/lolmaus/repos","events_url":"https://api.github.com/users/lolmaus/events{/privacy}","received_events_url":"https://api.github.com/users/lolmaus/received_events","type":"User","site_admin":false},"labels":[{"id":270543603,"url":"https://api.github.com/repos/andrewplummer/Sugar/labels/ES6","name":"ES6","color":"5319e7","default":false},{"id":260014438,"url":"https://api.github.com/repos/andrewplummer/Sugar/labels/Feature","name":"Feature","color":"207de5","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/andrewplummer/Sugar/milestones/5","html_url":"https://github.com/andrewplummer/Sugar/milestones/2.0.0","labels_url":"https://api.github.com/repos/andrewplummer/Sugar/milestones/5/labels","id":1303610,"number":5,"title":"2.0.0","description":null,"creator":{"login":"andrewplummer","id":74646,"avatar_url":"https://avatars.githubusercontent.com/u/74646?v=3","gravatar_id":"","url":"https://api.github.com/users/andrewplummer","html_url":"https://github.com/andrewplummer","followers_url":"https://api.github.com/users/andrewplummer/followers","following_url":"https://api.github.com/users/andrewplummer/following{/other_user}","gists_url":"https://api.github.com/users/andrewplummer/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewplummer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewplummer/subscriptions","organizations_url":"https://api.github.com/users/andrewplummer/orgs","repos_url":"https://api.github.com/users/andrewplummer/repos","events_url":"https://api.github.com/users/andrewplummer/events{/privacy}","received_events_url":"https://api.github.com/users/andrewplummer/received_events","type":"User","site_admin":false},"open_issues":35,"closed_issues":39,"state":"open","created_at":"2015-09-14T05:23:15Z","updated_at":"2016-11-24T12:53:51Z","due_on":null,"closed_at":null},"comments":9,"created_at":"2014-10-30T14:12:30Z","updated_at":"2016-11-24T12:53:51Z","closed_at":"2016-11-24T12:53:51Z","body":"In Ruby you can create an array by passing to `Array.new` the following:\n- a number of items\n- a constructor function that creates a single element of the array and accepts its index\n\nExample:\n\n``` rb\nfoo = Array.new(4) { |index|\n  index ** 2\n}\n\n# => [0, 1, 4, 9]\n```\n\nIt is extremely convenient.\n\nSugar happens to have its own array [constructor](http://sugarjs.com/api/Array/create), but it's kinda useless. :(\n\nMy current workaround with CoffeeScript is the following:\n\n``` coffee\nfoo = [0..4].map (index) ->\n  index * index\n\n# => [0, 1, 4, 9]\n```\n\nIt works perfectly, but it's harder to grasp. I prefer my code to be as self-explanatory as possible.\n\nMy suggestion is to create a new method working like in Ruby:\n\n``` js\nArray.construct( 4, function(index) {\n  return index * index;\n});\n// => [0, 1, 4, 9]\n```\n\nI would suggest doing that for the existing `.create`, but there seems to be no way to do that without breaking compatibility. :(\n"}}
{"actor":{"display_login":"andrewplummer"}}