Skip to content

Instantly share code, notes, and snippets.

@MacksMind
Created April 26, 2015 13:24
Show Gist options
  • Save MacksMind/0057959f76edd2c566fb to your computer and use it in GitHub Desktop.
Save MacksMind/0057959f76edd2c566fb to your computer and use it in GitHub Desktop.
# 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
@wakproductions
Copy link

Nice idea!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment