Radek Radek - 2 months ago 11
Ruby Question

How to iterate through an array starting from the last element? (Ruby)

I came with below solution but I believe that must be nicer one out there ...

array = [ 'first','middle','last']

index = array.length
array.length.times { index -= 1; puts array[index]}

Answer
array.reverse.each { |x| puts x }
Comments