I have an array with integers +20000.
I want to create a new array in which each element in the old array will add a modifier number. In a small array of samples, it will look like this:
old_array = [2,5,6,8]
modifying_number = 3
new_array = [5,8,9,11]
Is there a more efficient way than doing an iteration?
class Array
def addition_by(x)
collect { |n| n + x }
end
end
source
share