Created
August 1, 2011 22:19
-
-
Save hrstt/1119133 to your computer and use it in GitHub Desktop.
extract duplicate value in array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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