Skip to content

Instantly share code, notes, and snippets.

@cscheib
Last active September 3, 2015 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cscheib/b9f5a523a0acf375760e to your computer and use it in GitHub Desktop.
Save cscheib/b9f5a523a0acf375760e to your computer and use it in GitHub Desktop.
def count(array)
result = {}
array.uniq.each { |e| result[e] = array.count(e) }
end
p count(['a', 'a', 'b', 'b', 'b'])
arctistor:rubylearning chris$ ruby element_count.rb
["a", "b"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment