Q:

Write a Ruby program to iterate an array starting from the last element

0

Write a Ruby program to iterate an array starting from the last element.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

nums = [10, 20, 30, 40, 10, 10, 20]
print "Original array:\n"
print nums
print "\nReverse array:\n"
nums.reverse.each { |x| puts x }

Output:

Original array:
[10, 20, 30, 40, 10, 10, 20]
Reverse array:
20
10
10
40
30
20
10

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now