I have two arrays:
arr1 = [10,20,7]
arr2=[]
On the first array I am performing a division calculation similar to this:
arr1.each do |i|
res = i.to_f/2.0
arr2.push(res.round)
end
This will return arr2 = [5,10,4]
From the output array again I want to compare with the first array i.e [10,20,7]
If the output array arr2 contains value from any of the value from arr1
I want to replace that value with value/2.0
I am able to do a comparison like below:
arr2.any?{|x| arr1.include?(x)}
But I want to replace that value after comparing. How can I do that?