We often need to find the dulicate values in array.
Like the follows:
["A", "B", "C", "B", "A"] # => "A" or "B"
["A", "B", "C"] # => nil
How to do it?
arr = ["A", "B", "C", "B", "A"]
arr.detect{ |e| arr.count(e) > 1 }
FYI:
We often need to find the dulicate values in array.
Like the follows:
["A", "B", "C", "B", "A"] # => "A" or "B"
["A", "B", "C"] # => nil
How to do it?
arr = ["A", "B", "C", "B", "A"]
arr.detect{ |e| arr.count(e) > 1 }
FYI: