Created
August 20, 2014 16:10
-
-
Save kisai/5a217c95cf2daf261bef to your computer and use it in GitHub Desktop.
Find duplicates in a 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
ary = ["A", "B", "C", "B", "A"] | |
ary.group_by { |e| e }.select { |k, v| v.size > 1 }.map(&:first) | |
ary.sort.chunk { |e| e }.select { |e, count| count.size > 1 }.map(&:first) | |
ary.select { |e| ary.count(e) > 1 }.uniq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment