I wrote the following code
a = [2,4,6]
def add_value_and_index(anArray)
newArray = []
anArray.each_with_index do |element, index|
total = element + index
total
newArray <<"#{total}"
newArray
end
newArray
#newArray.to_i does not work
end
add_value_and_index(a)
This should return an array which is a combination of the index number and the value. The method works. I however get an output in strings => ["3","5"...] while I want it in integers => [1,2,3].
I tried to add newArray.to_i but this does not work. Any thoughts on how I can turn this array into integers?