I am wondering if this makes sense or the syntax is incorrect and, in principle, if it is acceptable. I would like to set an if / else condition within my array iteration.
def change_numbers(first_array, second_array)
second_array.each do |index|
if first_array[index] == 0
first_array[index] = 1
else
first_array[index] = 0
end
end
end
An array is a simple (binary) array and will consist of only 0 and 1, and I want to use the second element of the array as indices of the first array, which I am going to change.
Example:
first_array = [0, 0, 0, 0, 1, 1, 1, 1, 1]
second_array = [3, 5, 7]
Result:
first_array = [0, 0, 0, 1, 1, 0, 1, 0, 1]
source
share