I have this array of arrays:
arr =[["twitter.com", 9], ["twitter.com", 9], ["google.com", 11], ["paypal.me", 11],
["twitter.com", 11], ["yahoo.com", 12], ["google.com", 14], ["twitter.com", 17],
["twitter.com", 18], ["youtube.com", 31]]
How can I extract the arrays that have duplicate strings and get:
[["twitter.com", 9], ["twitter.com", 9], ["google.com", 11], ["twitter.com", 11],
["google.com", 12], ["twitter.com", 17], ["twitter.com", 18]]
Then add the value of the strings that are duplicate:
[["twitter.com", 64], ["google.com", 25]]
And end up with a new array :
[["twitter.com", 64], ["youtube.com", 31], ["google.com", 25],
["yahoo.com", 12],["paypal.me", 11]]
I tried:
array.select{|element| array.count(element) > 1 }
But was getting: [["twitter.com", 9], ["twitter.com", 9]