You can iterate reversed array with indexes, and then reverse result Array#reverse
i % 3 is used to multiply each 3rd element.
Error undefined method *' for nil:NilClass (NoMethodError) in your example appears because array.length is 16(elements in array), but indexes starts from 0, so last index is 15, and in the first iteration you are trying to access array[16] that does not exist, so it is nil
array = [4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2]
result = array.reverse.each_with_index.map do |x, i|
(i % 3).zero? ? x * 2 : x
end.reverse
# p result
#=> [8, 2, 4, 4, 4, 2, 8, 2, 4, 4, 4, 2, 8, 2, 4, 4]
UPDATE: Sekalf Nroc's answer is good with odd? if you need each 2nd element to multiply, but if you had for example 15 elements, you could see unexpected results, so reverse still needed to walk array backwards, by combining those approaches, you can do something like this:
array = [4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 99]
p array.map.with_index { |n, i| i.odd? ? n * 2 : n } # WRONG RESULT
#=>[4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 99]
p array.reverse.map.with_index { |n, i| i.even? ? n * 2 : n }.reverse
#=>[8, 2, 8, 2, 8, 2, 8, 2, 8, 2, 8, 2, 8, 2, 8, 2, 198]
array[index] * 2andindex - 2expressions, you need to assign them to something:array[index] *= 2,array[index] = array[index] * 2,index = index - 2,index -= 2, ...array.length - 1(remember, arrays are 0-indexed). Also you are not doing anything witharray[index] * 2(either print it, or assign to a variable)[4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2], what did you expect the output to be? I had interpreted the phrase "every second element" to mean the result should be[4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]. Is that right?