I'm performing operations on arrays and I'm running into some issues. I duplicated array_1 assigning it to array_2. When I did operations on array_2, the uniq method modifies the original array.
array_3 is what I intended accomplish, but I don't understand why the operations to get there modified array_1
I need an explanation why this behavior occurs, and what I can do to prevent this from happening.
array_1 = [["Ed","2",],["Ann","2"],["Sue","2"],["Ed","3",],["Ann","3"],["Sue","3"]]
array_2 = array_1.dup
array_2 = array_2.uniq(&:first)
array_3=[]
array_2.each do |a2|
a2.pop
array_3.push(a2)
end
puts array_3
=> [["Ed"], ["Ann"], ["Sue"]]
puts array_1
=> [["Ed"], ["Ann"], ["Sue"], ["Ed", "3"], ["Ann", "3"], ["Sue", "3"]]