I need to perform an operation on k set of values of an array and return the modified array.
I have an array = [10,32,5,6,7]
Let us say k=2
I am trying to take only the first two elements here by doing:
arr2=[]
array[0..k-1].each do |i|
res=i.to_f/2.0
arr2.push(res.round)
end
=>arr2=[5,16]
I want to replace the first 2 elements in the array with arr2 values.
How can I achieve this without having to create so many new arrays.