From: Gavin Kistner Date: 2006-10-28T02:54:36+09:00 Subject: Re: how to get only the duplicatet items from an array From: Nico Landgraf [mailto:nico@nico-landgraf.de] > is there a oneline to get only the duplicatet item from an array? > > i have an array like this > aTemp = [1, 1, 2, 2, 3, 4] > and i want to know, which items are duplicatet. There are faster ways to do this, but since you asked for a one-line: a = [1, 1, 2, 2, 3, 4] duplicates = a.delete_if{ |x| a.grep(x).length == 1 }.uniq #=> [1, 2]