[#91458] [Ruby trunk Feature#4475] default variable name for parameter — matz@...
Issue #4475 has been updated by matz (Yukihiro Matsumoto).
3 messages
2019/02/07
[ruby-core:91491] [Ruby trunk Feature#15590] Add dups to Array to find duplicates
From:
nobu@...
Date:
2019-02-08 10:00:31 UTC
List:
ruby-core #91491
Issue #15590 has been updated by nobu (Nobuyoshi Nakada).
sawa (Tsuyoshi Sawada) wrote:
> ```ruby
> a.tally(&:itself).flat_map{|k, v| Array.new(v - 1, k)}
> ```
As `tally` does not take a block, `&:itself` is not used.
It's a mistake in the rdoc.
----------------------------------------
Feature #15590: Add dups to Array to find duplicates
https://bugs.ruby-lang.org/issues/15590#change-76752
* 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>