Skip to content

Instantly share code, notes, and snippets.

@joegiralt
Last active August 29, 2015 14:27
Show Gist options
  • Save joegiralt/6ff35a21ea810e27a607 to your computer and use it in GitHub Desktop.
Save joegiralt/6ff35a21ea810e27a607 to your computer and use it in GitHub Desktop.
count duplicate items in array ()
array = ['jim','jack','joe','larry','larry','larry','larry','larry', 'joe']
def count_items(array)
hash = {}
array.each do |name|
if hash[name]
hash[name] = hash[name] + 1
else
hash[name] = 1
end
end
puts hash
end
count_items(array)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment