Skip to content

Instantly share code, notes, and snippets.

@barunthapa
Created July 23, 2013 11:32
Show Gist options
  • Save barunthapa/6061698 to your computer and use it in GitHub Desktop.
Save barunthapa/6061698 to your computer and use it in GitHub Desktop.
Extracts the indexes of the duplicate elements including the original element
def duplicate_index(array)
size = array.size
duplicate = []
duplicate_indexes = []
array.uniq.each do |a|
duplicate_index = []
size.times do |i|
duplicate_index << i if array[i] == a
end
duplicate << duplicate_index if duplicate_index.size > 1
end
duplicate
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment