Created
April 26, 2015 13:24
-
-
Save MacksMind/0057959f76edd2c566fb to your computer and use it in GitHub Desktop.
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
# Takes an array (enumerable?) as input | |
# Return an array containing elements occurring multiple times in input | |
def report_duplicate_elements(list) | |
occurs_multiple_times = [] | |
already_seen = [] | |
list.each do |element| | |
if already_seen.include?(element) | |
occurs_multiple_times << element | |
else | |
already_seen << element | |
end | |
end | |
# Discard dups from elements occurring more that twice | |
occurs_multiple_times.uniq | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice idea!