Skip to content

Instantly share code, notes, and snippets.

@hrstt
Created August 1, 2011 22:19
Show Gist options
  • Save hrstt/1119133 to your computer and use it in GitHub Desktop.
Save hrstt/1119133 to your computer and use it in GitHub Desktop.
extract duplicate value in array
a = [1,2,3,4,5,6,4,5]
a.inject(Hash.new 0) {|h,v| h[v]+= 1;h}.select {|h,v| v >= 2}.keys #=> [4,5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment