Skip to content

Instantly share code, notes, and snippets.

@iNecas
Created February 21, 2011 12:44
Show Gist options
  • Save iNecas/837012 to your computer and use it in GitHub Desktop.
Save iNecas/837012 to your computer and use it in GitHub Desktop.
finding duplicities in array in one line
comps = ["PC", "MAC", "PC", "PC", "LINUX", "MAC", "DIDAKTIK"]
duplicities = comps.group_by{|x| x.first}.find_all{|k,v| v.size > 1}.map{|x| x.first}
duplicities # => ["MAC","PC"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment