Issue #15590 has been updated by shevegen (Robert A. Heiler).


I am not entirely sure whether I understood the proposal or the code example.

What do you mean with duplicated values in an Array? Do you mean something
"reversed" such as a complementary method to .uniq (Array#uniq)? Or is the
suggestion related to Object#dup? https://ruby-doc.org/core-2.6.1/Object.html#method-i-dup

I assume that you more refer to a complementary method to .uniq but I am not
completely sure, so I hope it's ok for you to clarify on that just to make sure, when
you have some time.

(We may also have to look at the chosen name for the method; I am not sure if
.dups would be an acceptable method due to potential confusion.)

----------------------------------------
Feature #15590: Add dups to Array to find duplicates
https://bugs.ruby-lang.org/issues/15590#change-76686

* Author: xdmx (Eric Bloom)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Many times I find myself debugging data and the need of finding duplicated values inside of an Array.

Based on the amount of data it could be a simple `array.detect { |value| array.count(value) > 1 }` or a more performant way like

```ruby
def dups_for(array)
  duplicated_values = []
  tmp = {}
  array.each do |value|
    duplicated_values << value if tmp[value]
    tmp[value] = true
  end
  duplicated_values
end
```
 
It would be awesome if there was a way directly from the core language to call `dups` (or another name, as it could be too similar to the current `dup`) on an array in order to get all the duplicated values.

I'd love to create a PR for this, but my C level is non-existent 




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>