I'm trying to display only the duplicate value in an array which just holds names.
So for instance, my code is:
<%= s= arrayOfStuff %>
<%= t= arrayOfStuff.uniq %>
which displays
["UK01USV005", "NJ08APP516", "NJ08MHF001", "UK01USV505", "NY01MHF0006", "UK01USV525", "UK01USV005", "NJ08APP515", "NJ08MHF002"]
["UK01USV005", "NJ08APP516", "NJ08MHF001", "UK01USV505", "NY01MHF0006", "UK01USV525", "NJ08APP515", "NJ08MHF002"]
so theortically when I do s-t
it should give me the duplicate value which in this case is UK01USV005
, however the results I get is an empty array which obviously looks like this: []
.
Any ideas why that could be?
arrayOfStuff.group_by {|e| e}.select { |k,v| v.size > 1}.keys
should work fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With