From: "Jan E." Date: 2012-04-20T07:49:49+09:00 Subject: Re: finding duplicates in an array and its index number Hi, As always, there are many ways to do this. A highlevel approach: (short but not really inefficient) #### x = [1, 2, 3, 2, 4, 5, 4, 4] a = x.each_with_index.group_by(&:first).inject({}) do |result, (val, group)| next result if group.length == 1 result.merge val => group.map {|pair| pair[1]} end p a #### A more efficient lowlevel solution would be to iterate over the array, compare the values and save the indices in case of duplicates. -- Posted via http://www.ruby-forum.com/.