I have an array that’s acting weird, it starts as an empty array, I call
it “final_array”, and then I append a small array of only two members to
it, just called “array”, and that works fine. Then I swap the two
members of “array”, and they also swap inside “final_array”. It’s like
they’re linked together.
What am I doing wrong? Any help is greatly appreciated.
Here is my code…
array = [1,2]
final_array = []
append…
final_array << array
swap…
second_to_max_index = array.length - 2
max_index = array.length - 1
holder = array[second_to_max_index]
puts “----final array is #{final_array}”
array[second_to_max_index] = array[max_index]
puts “----final array is #{final_array}”
array[max_index] = holder
puts “----final array is #{final_array}”
Here is the output…
----final array is [[1, 2]]
----final array is [[2, 2]]
----final array is [[2, 1]]
