Created
July 23, 2013 11:32
-
-
Save barunthapa/6061698 to your computer and use it in GitHub Desktop.
Extracts the indexes of the duplicate elements including the original element
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
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