On 10/28/07, Shuaib Zahda <shuaib.zahda / gmail.com> wrote: > Hello > > I am trying to output the duplicate elements in an array. I looked into > the api of ruby I found uniq method which outputs the array with no > duplication. What i want is to know which elements is duplicated. > For example > > array = ["apple", "banana", "apple", "orange"] > => ["apple", "banana", "apple", "orange"] > array.uniq > => ["apple", "banana", "orange"] > > I want the method to tell me that apple is the duplicated element > > I tried this but it does not work > > array - array.uniq > > any idea > > Regards > Shuaib > -- > Posted via http://www.ruby-forum.com/. > > arr,dup = ["apple", "banana", "apple", "orange"],[] (arr.length-1).times do a = arr.shift dup << a if arr.include?(a) end p dup.uniq Harry -- A Look into Japanese Ruby List in English http://www.kakueki.com/