Created
July 9, 2010 04:11
-
-
Save daveed/469026 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
module Enumerable | |
def dups | |
inject({}) {|h,v| h[v]=h[v].to_i+1; h}.reject{|k,v| v==1}.keys | |
end | |
end | |
# arr = [2,8,8,42,7,33,42] | |
# puts arr.dups.inspect | |
# [8, 42] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
source: http://snippets.dzone.com/posts/show/3838
Thanks.