{"id":20687871,"url":"https://github.com/cribbles/array_each_count","last_synced_at":"2025-09-25T12:34:09.991Z","repository":{"id":31601475,"uuid":"35166356","full_name":"cribbles/array_each_count","owner":"cribbles","description":"Ruby code kata designed for RSpec","archived":false,"fork":false,"pushed_at":"2015-05-30T02:43:27.000Z","size":196,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-17T16:52:40.101Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cribbles.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-06T15:17:40.000Z","updated_at":"2015-10-03T19:51:07.000Z","dependencies_parsed_at":"2022-09-10T00:52:02.001Z","dependency_job_id":null,"html_url":"https://github.com/cribbles/array_each_count","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cribbles%2Farray_each_count","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cribbles%2Farray_each_count/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cribbles%2Farray_each_count/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cribbles%2Farray_each_count/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cribbles","download_url":"https://codeload.github.com/cribbles/array_each_count/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242945838,"owners_count":20210762,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T22:58:30.146Z","updated_at":"2025-09-25T12:34:09.886Z","avatar_url":"https://github.com/cribbles.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Array#each_count\n\nA simple Ruby code kata designed for rspec, inspired by Alex Chaffee's [Test First Ruby](https://github.com/alexch/learn_ruby).\n\n## Description\n\nCreate a method, `Array#each_count`, which returns a count of discrete elements contained in the form of `{element =\u003e count}`.\n\nYour method should meet the following criteria:\n\n* When called without arguments or a block, it should iterate over each element of _self_, returning a count of its unique elements.\n\n* It should accept a method (in symbol or string format) followed by any number of arguments as parameters. It should apply these parameters to each element of _self_, returning a count of each unique return value.\n\n* It should accept a block, call the block on each element of _self_, and return a count of each unique return value.\n\n* It should raise an exception if both arguments and a block are provided.\n\n## Examples\n\nGiven an array _cities_:\n\n``` ruby\ncities = [\"Melbourne\", \"Dallas\", \"Taipei\", \"Toronto\", \"Dallas\", \"Kathmandu\"]\n```\n\n**`cities.each_count`** should return:\n\n``` ruby\n# =\u003e {\"Melbourne\"=\u003e1, \"Dallas\"=\u003e2, \"Taipei\"=\u003e1, \"Toronto\"=\u003e1, \"Kathmandu\"=\u003e1}\n```\n\n**`cities.each_count :length`** should return:\n\n``` ruby\n# =\u003e {9=\u003e2, 6=\u003e3, 7=\u003e1}\n```\n\n**`cities.each_count :gsub, /[aeiou]/, 'x'`** should return:\n\n``` ruby\n# =\u003e {\"Mxlbxxrnx\"=\u003e1, \"Dxllxs\"=\u003e2, \"Txxpxx\"=\u003e1, \"Txrxntx\"=\u003e1, \"Kxthmxndx\"=\u003e1}\n```\n\n**`cities.each_count {|city| city.length % 3 == 0}`** should return:\n\n``` ruby\n# =\u003e {true=\u003e5, false=\u003e1}\n```\n\n## More Examples\n\nExamples are provided as test cases in the /spec directory.  Your goal is to factor your solution to get all of the tests to pass.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcribbles%2Farray_each_count","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcribbles%2Farray_each_count","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcribbles%2Farray_each_count/lists"}